【问题标题】:Roblox leaderstat only updates onceRoblox leaderstat 只更新一次
【发布时间】:2020-10-30 13:04:19
【问题描述】:

我试图用 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)

【问题讨论】:

  • 你为什么要禁用脚本?

标签: roblox datastore


【解决方案1】:

您遇到与this guy 相同的问题。

当您基于 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"

【讨论】:

  • 感谢这工作完美,我不敢相信我看过了。
猜你喜欢
  • 2022-10-20
  • 2022-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多