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

Attempting to change the value of a value error?[Easily Solved]

I am trying to make a game and the value of the cost won't go up. The error is one that I have never gotten before. Error: Players.Player1.PlayerGui.BuyGui.BuyFrame.ImageButton.Buy:6: attempt to perform arithmetic on upvalue 'cost' (a userdata value)

local persec = script.Parent.Parent.Parent.Parent.ClickGui.PerSec
local money = script.Parent.Parent.Parent.Parent.ClickGui.Number
local cost = script.Parent.Cost

script.Parent.MouseButton1Click:connect(function()
	if money.Value > (cost - 1) then
		persec.Value = persec.Value + 0.1
		money.Value = money.Value - cost
		cost.Value = cost.Value + (cost.Value * 1.06)
	end
end)

1 answer

✓ Accepted answer

You wrote

money.Value = money.Value - cost

But cost is a NumberValue object. You can't add ROBLOX objects -- that wouldn't make sense (this is the error -- a NumberValue is a userdata)

You should have written cost.Value

That same goes for line 6.

3 comments

0

A simple mistake. Thanks. I completely forgot about the value of the number. :3

0

BlueTaslem. Whenever I buy the thing it always makes the perSec value go up by 0.10000000023278. or something like that. Is there a way to prevent this? Or is there a simple script that I could use? If there is a script could you post it?

0

That is 0.1, or as accurately as ROBLOX's number system can represent it. You'll just have to deal with that value wherever you see it -- if it's messing up display, try different rounding techniques (you should be able to find them on this site)

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