local tool = game.Lighting.M249 script.Parent.ClickDetector.mouseClick:connect (function(plr) local yes = tool:Clone() yes.Parent = plr.Backpack end)
You're gonna have to fix the case when indexing the MouseClick
property, and add an if
statement that checks the player's money. After that the script should function properly.
Note: Lighting isn't meant for storage, use ReplicatedStorage.
local tool = game.ReplicatedStorage.M249 local amount = 1100 script.Parent.ClickDetector.MouseClick:connect(function(plr) local stat = plr.leaderstats:FindFirstChild("Money") if stat.Value >= amount then --Check if the player has enough local yes = tool:Clone() yes.Parent = plr.Backpack stat.Value = stat.Value - amount --Subtract money end end)
You are close
local player = game.Players.LocalPlayer local tool = game.Lighting.M249 script.Parent.ClickDetector.MouseClick:Connect(function(plr) local yes = tool:Clone() yes.Parent = plr.Backpack if (player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") and (player.leaderstats.Money.Value > 0)) then player.leaderstats.Money.Value = (player.leaderstats.Money.Value - 1100); end end)