Roblox leaderstat 只更新一次

Roblox leaderstat only updates once

每次玩家打出可损坏的物体(出气筒、假人等)时,我都会尝试用 exp 奖励玩家。每当比赛打出某物时,它只会更新 exp leaderstat 一次,有谁知道我在做什么做错了吗?

我的脚本:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Touched:Connect(function(hit)
    local Char = hit.parent
    local Hum = Char:FindFirstChild("Humanoid")
    if Hum and Char.Name ~= script.Parent.Parent.Name then
        local Indicator = require(game.ReplicatedStorage.DamageIndicator)
        local Player = script.Parent.Parent
        local LocalPlayer = game.Players:GetPlayerFromCharacter(Player)
        local Exp = LocalPlayer.leaderstats.Experience.Value
        Hum:TakeDamage(script.Dmg.Value)
        Indicator.DamageActivate(script.Dmg.Value, hit)
        Exp = Exp + 15
        LocalPlayer.PlayerGui.UI.Experience.ExpBar.Size = UDim2.new((Exp / 100) * 0, 0, 0.02, 0)
        LocalPlayer.PlayerGui.UI.Experience.ExpBackground.ExpAmt.Text = Exp.."/100"
        script.Disabled = true
    end
end)

您遇到的问题与 相同。

当您基于 NumberValue 的值创建变量时,您存储的是该值的副本,而不是对其的引用。如果要更新值,需要手动赋值。

local Exp = LocalPlayer.leaderstats.Experience
Exp.Value = Exp.Value + 15

local ExpGui = LocalPlayer.PlayerGui.UI.Experience
ExpGui.ExpBar.Size = UDim2.new((Exp.Value / 100) * 0, 0, 0.02, 0)
ExpGui.ExpBackground.ExpAmt.Text = tostring(Exp.Value) .. "/100"