local tool = game.Lighting.M249
script.Parent.ClickDetector.mouseClick:connect (function(plr)
local yes = tool:Clone()
yes.Parent = plr.Backpack
end)
✓ ANSWER ACCEPTED
Need to make it so the "Money" in 'leaderstats' in the game deducts 1100 when clicked (>=1100)?
2 answers
✓ Accepted answer
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)
3 comments
0
thanks it worked! but the only reason i put it in lighting is because i had some other things in replicated storage i didn't want to get mixed up with
0
Ah ok cool. Glad I could help :D
0
ok
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)
2 comments
0
Workspace.buy m249.Script:7: attempt to index upvalue 'player' (a nil value) is what the out put said
0
Must be how you are putting the script in.... Works perfectly fine for my game.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Have you made an attempt at this?
yes have
Well, did it work?
Is it working now?If not ill start working on the script myself and find out whats wrong.