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

What does it mean to attempt to index upvalue (a number)?

Asked by 5 years ago

What I want my code to do is find if the player's currency amount is the same or greater than the cost of the item they are trying to buy. If it isn't then it should pop up with a text label that I made. If they have enough money then the script should change the value of a certain integer value that I will process later and should make the cost 1.4 times as much as it was before. When the player doesn't have enough currency the script opens the label for 2 seconds then makes it disappear. When the player has enough money an error pops up. The error is : Players.CarmiteStars.PlayerGui.Menu.MenuFrame.WorkerShopOpener.WorkerShopFrame.NoobScripter.Worker1Purchase:6: attempt to index upvalue 'robux' (a number value).

local robux = game.Players.LocalPlayer.stats.robux

local buybutton = script.Parent

local WorkerCost = game.Players.LocalPlayer.gen.Worker1Cost

local Worker1Cash = game.Players.LocalPlayer.gen.Worker1Production

buybutton.MouseButton1Down:Connect(function()

if robux.Value < WorkerCost.Value then

buybutton.Parent.Worker1Fail.Visible = true

wait(2)

buybutton.Parent.Worker1Fail.Visible = false

else

robux = robux.Value - WorkerCost.Value

wait(.5)

WorkerCost = WorkerCost.Value * 1.4

Worker1Cash = Worker1Cash.Value + 1

end

end)
0
line 21 do robux.Value = robux.Value - WorkerCost.Value Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
local robux = game.Players.LocalPlayer.stats.robux
local buybutton = script.Parent
local WorkerCost = game.Players.LocalPlayer.gen.Worker1Cost
local Worker1Cash = game.Players.LocalPlayer.gen.Worker1Production
buybutton.MouseButton1Down:Connect(function()
if robux.Value < WorkerCost.Value then
buybutton.Parent.Worker1Fail.Visible = true
wait(2)
buybutton.Parent.Worker1Fail.Visible = false
else
robux.Value = robux.Value - WorkerCost.Value
wait(.5)
WorkerCost.Value = WorkerCost.Value * 1.4
Worker1Cash.Value = Worker1Cash.Value + 1
end
end)

On multiple lines, you are trying to index an upvalue which is invalid/doesn't exist. You forgot the ".Value" on the first "robux" and workers. (man i really get the explanations wrong.)

0
Thanks so much! CarmiteStars 9 — 5y
Ad

Answer this question