Roblox Studio Lua问题“;Workspace.Ultimate.Script:12:尝试比较数字<;“字符串”-

Roblox Studio Lua问题“;Workspace.Ultimate.Script:12:尝试比较数字<;“字符串”-,lua,compare,roblox,Lua,Compare,Roblox,我被困在这一点上,我尝试了很多东西,但都没有奏效。结果如下: deb = true giv = script.Parent.Giver function touch(part) local hum = part.Parent:FindFirstChild("Humanoid") if hum then local plr = game.Players:FindFirstChild(part.Parent.Name) local

我被困在这一点上,我尝试了很多东西,但都没有奏效。结果如下:

deb = true
giv = script.Parent.Giver
function touch(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum then
        local plr = game.Players:FindFirstChild(part.Parent.Name)
        local ls = plr:FindFirstChild("leaderstats")
        local cash = ls:FindFirstChild("Cash")
        if plr then
            if deb == true then
                if cash.Value > 12500 then
                deb = false
                giv.BrickColor = BrickColor.new("Really red")
                    local weapon = game.ReplicatedStorage.Jutsus:FindFirstChild("Fireball")
                local w2 = weapon:Clone()
                w2.Parent = plr.Backpack
                wait(script.Parent.RegenTime.Value)
                giv.BrickColor = BrickColor.new("Bright violet")
                    deb = true
                end
            end
        end
    end
end
script.Parent.Giver.Touched:connect(touch) 
Workspace.Ultimate.Script:12:尝试比较编号

如果有人能为我改进代码,我将不胜感激。

显然
cash.Value
是一个字符串,因此您无法执行
cash.Value>12500

cash.Value
转换为数字,然后再将其与数字进行比较

tonumber(cash.Value)>12500


此解决方案假定
cash.Value
是表示数字的字符串。如果不是这种情况,您必须首先确保。

字符串和数字比较需要提前转换,并且您需要确保
casg.Value
必须是数字,否则可能会提示您与零值进行比较

然后你可以写这样的代码

Workspace.Ultimate.Script:12: attempt to compare number < string  -  Server - Script:12
deb = true
giv = script.Parent.Giver
function touch(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum then
        local plr = game.Players:FindFirstChild(part.Parent.Name)
        local ls = plr:FindFirstChild("leaderstats")
        local cash = ls:FindFirstChild("Cash")
        if plr then
            if deb == true then
                if (tonumber(cash.Value) or 0) > 12500 then
                    deb = false
                    giv.BrickColor = BrickColor.new("Really red")
                    local weapon = game.ReplicatedStorage.Jutsus:FindFirstChild("Fireball")
                    local w2 = weapon:Clone()
                    w2.Parent = plr.Backpack
                    wait(script.Parent.RegenTime.Value)
                    giv.BrickColor = BrickColor.new("Bright violet")
                    deb = true
                end
            end
        end
    end
end
script.Parent.Giver.Touched:connect(touch)