Hello everyone! What I attempted to create was a script where if a button is pressed, it would take away the money and clone the item to the players backpack. The problem is, when I tested it out in studio, it would always decline, even if it's over the designated price.
I created a module in serverscriptservice, where it creates a folder in the player, which I defined as funds in the following code.
Shop Local Script :
local amount = 2400 local player = game.Players.LocalPlayer local Funds = game.Players.LocalPlayer.Stats.Money.Value script.Parent.MouseButton1Click:connect(function() print("Button1 Clicked") if Funds >= amount and not player.Backpack:FindFirstChild("ClassicSword") then game.ReplicatedStorage["ClassicSword"]:Clone().Parent = game.Players.LocalPlayer.Backpack print("Sword bought") else print("Insufficient Funds") end end)
Any help is appreciated. Also, could you please explain the way you would fix it, because I just started scripting so I may not understand your methods.
Your problem is that you are making the variable as the value and that you are only setting the variable once (at the beginning, before the function).
you can easily fix this by moving .Value
in the function.
local amount = 2400 local player = game.Players.LocalPlayer -- you weren't using this variable before local Funds = player:WaitForChild("Stats"):WaitForChild("Money") script.Parent.MouseButton1Click:connect(function() print("Button1 Clicked") if Funds.Value >= amount and (not player.Backpack:FindFirstChild("ClassicSword")) then game.ReplicatedStorage["ClassicSword"]:Clone().Parent = game.Players.LocalPlayer.Backpack print("Sword bought") else print("Insufficient Funds") end end)