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

how to fix this roblox error? attempt to perform arithmetic (add) on userdata and number.

Asked by 4 years ago

I am new on the coding and I keep getting a message saying: "attempt to perform arithmetic (add) on userdata and number"

local Price = 20
local MoneyValue = game.ServerScriptService.CurrencyRiser:WaitForChild("amount")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Cash.Value >= Price then
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - Price
            MoneyValue = MoneyValue + 1
            script.Parent:Destroy()
        end
    end
end)

how to i fix this error?

1 answer

Log in to vote
0
Answered by
qVoided 221 Moderation Voter
4 years ago

Try this:

local Price = 20
local MoneyValue = game.ServerScriptService.CurrencyRiser:WaitForChild("amount").Value -- You didn't put .Value, it should fix it.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.leaderstats.Cash.Value >= Price then
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - Price
            MoneyValue = MoneyValue + 1
            script.Parent:Destroy()
        end
    end
end)

Ad

Answer this question