Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My selling script is not working? pls help. Error attempt to compare number with string

Asked by 4 years ago

Why doesn't this work?

Error: Workspace.SellPlace.SellPart.Script:10: attempt to compare number with string

local Part = script.Parent
Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid") 
    if H then
        local player = game.Players:GetPlayerFromCharacter(HIT.Parent)  
if player then
    local leaderstats = player:WaitForChild("leaderstats")
    local Currency = leaderstats.Money 
    local Selling = leaderstats.Strength 
        if Selling.Value > 0 then
            Currency.Value = Currency.Value + Selling.Value *1 
            Selling.Value = 0
        end
end
end
end)


0
Tell me, are those values held by a number value or a string value? I_Nev 200 — 4y
0
String value BlueFlash2020 5 — 4y
0
Hello, there's no way to compare that "ABC" is greater than 0, unless you turn each letters to a specific numbers User#17685 0 — 4y
0
Dont mind the "unless" part :> User#17685 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

It seems like you made your strength value as a StringValue instead of IntValue. I also spotted a little mistake:

local Part = script.Parent
Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid") 
    if H then
        local player = game.Players:GetPlayerFromCharacter(HIT.Parent.Name)  -- You said HIT.Parent
if player then
    local leaderstats = player:WaitForChild("leaderstats")
    local Currency = leaderstats.Money 
    local Selling = leaderstats.Strength 
        if Selling.Value > 0 then
            Currency.Value = Currency.Value + Selling.Value *1 
            Selling.Value = 0
        end
end
end
end)

If this helped please thumbs up and accept this answer.

All the best,

PrismaticFruits

0
HIT.Parent is correct. Function finds a player from character model, and not by name. Dfzoz 489 — 4y
0
It didn't work but thx for helping BlueFlash2020 5 — 4y
0
I got this error: Unable to cast value to Object BlueFlash2020 5 — 4y
0
Then make sure your strength is an IntValue. PrismaticFruits 842 — 4y
Ad

Answer this question