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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

0
A simple mistake. Thanks. I completely forgot about the value of the number. :3 raystriker6707 30 — 10y
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? raystriker6707 30 — 10y
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) BlueTaslem 18071 — 10y
Ad

Answer this question