So, I made a LocalScript inside of an ImageButton that takes away from a value inside of a separate GUI and clones an item from Lighting and into a the clicker's backpack, but it doesn't seem to be working. I also cannot found any errors, so I was wondering if anyone could find something that I may have overlooked or screwed up on. Thanks for your time!
local money = game.Players.LocalPlayer.PlayerGui.MoneyGui.Frame.Amount.Money.Value local price = 5 script.Parent.MouseButton1Click:connect(function() if money >= price then money = money-5 local water = game.Lighting.Water:Clone() water.Parent = game.Players.LocalPlayer.Backpack print(game.Players.LocalPlayer.Name .. "has just bought Water!") end end)
#1, Try putting water in ReplicatedStorage.
#2, Change how you define money by getting rid of the .Value at the end
Using Lighting
to store items is a bad idea and just isn't used anymore. You also can't use .Value when defining Variables
. This is just how Roblox Lua works. The resulting code after moving water to ReplicatedStorage
and Changing
how you define money would look something like this,
local money = game.Players.LocalPlayer.PlayerGui:WaitForChild("MoneyGui"):WaitForChild("Frame"):WaitForChild("Amount"):WaitForChild("Money") --Remove.Value and add some Waits local price = 5 script.Parent.MouseButton1Down:connect(function() if money.Value >= price then --Use .Value when refurring to the variable's value money.Value = money - price local water = game.ReplicatedStorage.Water:Clone() --Move water to replicated storage water.Parent = game.Players.LocalPlayer.Backpack print(game.Players.LocalPlayer.Name .. "has just bought Water!") end end)
That should work. Good Luck!