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

arithmetic (add) on Instance and number?

Asked by 3 years ago
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        local plrLeader = player.leaderstats
        plrLeader.Tokens = plrLeader.Tokens + 1 
    end
end)

OUTPUT: attempt to perform arithmetic (add) on Instance and number

1 answer

Log in to vote
0
Answered by 3 years ago

Because Tokens is an IntValue(Instance). To get the value of the IntValue do; plrLeader.Tokens.Value.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        local plrLeader = player.leaderstats
        plrLeader.Tokens.Value = plrLeader.Tokens.Value + 1 
    end
end)
0
you can do plrLeader.Tokens.Value += 1 instead of plrLeader.Tokens.Value = plrLeader.Tokens.Value + 1 YAYYYYUGUY 0 — 3y
0
@YAYYYYUGUY doing it like that can get beginners a bit confused. MarkedTomato 810 — 3y
Ad

Answer this question