Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

arithmetic (add) on Instance and number?

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

✓ Accepted answer

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)

2 comments

0

you can do plrLeader.Tokens.Value += 1 instead of plrLeader.Tokens.Value = plrLeader.Tokens.Value + 1

0

@YAYYYYUGUY doing it like that can get beginners a bit confused.

This discussion is preserved as it was. New answers, comments, and votes are closed.