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

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

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

✓ Accepted answer

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)

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