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

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

Asked by 6 years ago
Edited 6 years ago

"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

Log in to vote
0
Answered by 6 years ago

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)
0
wanting to set the "Value" property** Gey4Jesus69 2705 — 6y
0
beat me to it by 26 seconds UnityAlex 36 — 6y
0
gottem Gey4Jesus69 2705 — 6y
0
Ohhhh.. I forgot to value thing, thanks for helping. DbExpress 20 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question