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

Workspace.Part.Script:5: attempt to perform arithmetic on local 'cash' (a userdata value)???

"19:25:14.186 - Workspace.Part.Script:5: attempt to perform arithmetic on local 'cash' (a userdata value)"

script.Parent.Touched:connect(function(hit)
	hit.Parent:WaitForChild("Humanoid")
	local plr = hit.Parent.PlayerLocation.Value
	local cash = plr.leaderstats.Cash
	cash = cash + 5
end)

Answered by: gioni01

script.Parent.Touched:connect(function(hit)
	hit.Parent:WaitForChild("Humanoid")
	local plr = hit.Parent.PlayerLocation.Value
	local cash = plr.leaderstats.Cash
	cash.Value = cash.Value + 5
end)

2 answers

✓ Accepted answer

You are trying to set the object "cash" to a new value, when you're wanting to set the value of its property.

script.Parent.Touched:connect(function(hit)
    hit.Parent:WaitForChild("Humanoid")
    local plr = hit.Parent.PlayerLocation.Value
    local cash = plr.leaderstats.Cash
    cash.Value = cash.Value + 5
end)

4 comments

0

wanting to set the "Value" property**

0

beat me to it by 26 seconds

0

gottem

0

Ohhhh.. I forgot to value thing, thanks for helping.

You are trying to access the cash value instance, not the value itself. Put a ".value" after Cash.

script.Parent.Touched:connect(function(hit)
    hit.Parent:WaitForChild("Humanoid")
    local plr = hit.Parent.PlayerLocation.Value
    local cash = plr.leaderstats.Cash
    cash.Value = cash.Value + 5
end)

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