player = script.Parent.Parent.Parent.Parent.Parent.Parent gold = player.leaderstats.Cash cost = script.Parent.Cost.Value getItem = game.Lighting.ErtYhop.Listed.ChezBurger function buy() if gold.Value >= cost then gold.Value = gold.Value - cost local a = getItem:clone() a.Parent = player.Backpack cost = 0 -- idk here wait(1) end script.Parent.ImageTransparency = 0.9 script.Parent.ImageColor3 = 21, 158, 165 wait(1) script.Parent.ImageTransparency = 0.3 end script.Parent.MouseButton1Down:connect(buy
) Hey Ho ! I wanna make this script to change value of 'cost' to 0 cost = 0 - idk here
Can You help me ? I'm new to lua :P
Make sure the parent of the script is TextButton and the script is LocalScript not normal script, nor ModuleScript.
script.Parent.MouseButton1Click:connect(function(buy) local Plr = game.Players.LocalPlayer local gold = Plr.leaderstats.Cash local cost = script.Parent.Cost local getItem = game.Lighting.Tool -- Your Tool Location if gold.Value >= cost.Value then gold.Value = gold.Value - cost.Value getItem:Clone().Parent = Plr.Backpack cost.Value = 0 wait(1) end -- Other Coding end)
Other then that GOOD2GO
When you set script.Parent.Cost.Value
to a variable, it only set the current value to that variable. When you set cost = 0
, you changed only the value of the variable, not Cost.Value
.
To change Cost.Value
, you must do it directly
Cost.Value = --whatever value you want
Hopefully this is what you are looking for. If you just wanted to change the variable cost
, it's as simple as what you already have
cost = 12345 -- or whatever number you want
player = script.Parent.Parent.Parent.Parent.Parent.Parent gold = player.leaderstats.Cash cost = script.Parent.Cost -- change this to just the item getItem = game.Lighting.ErtYhop.Listed.ChezBurger function buy() if gold.Value >= cost.Value then -- all places you use cost, now use cost.Value gold.Value = gold.Value - cost.Value local a = getItem:clone() a.Parent = player.Backpack cost.Value = 0 -- idk here wait(1) end script.Parent.ImageTransparency = 0.9 script.Parent.ImageColor3 = 21, 158, 165 wait(1) script.Parent.ImageTransparency = 0.3 end script.Parent.MouseButton1Down:connect(buy)