Code:
local Cost = script.Parent.Cost game.Players.PlayerAdded:Connect(function(plr) local BuyGUI = plr.PlayerGui:FindFirstChild("BuyGUI") if BuyGUI then BuyGUI.BuyFrame.Yes.MouseButton1Click:Connect(function() if plr.leaderstats.Cash.Value >= Cost then plr.leaderstats.Cash.Value -= Cost print("purchase successful") end end) end end)
There's no error, btw it's a normal Script
Try waiting for the Gui. (Also be more specific on your question)
local Cost = script.Parent.Cost -- // Assuming that this is an Int/NumberValue. game.Players.PlayerAdded:Connect(function(plr) local BuyGUI = plr.PlayerGui:WaitForChild("BuyGUI") BuyGUI.BuyFrame.Yes.MouseButton1Click:Connect(function() if plr.leaderstats.Cash.Value >= Cost.Value then plr.leaderstats.Cash.Value -= Cost.Value print("purchase successful") end end) end)