Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need to make it so the "Money" in 'leaderstats' in the game deducts 1100 when clicked (>=1100)?

local tool = game.Lighting.M249
script.Parent.ClickDetector.mouseClick:connect (function(plr)
	local yes = tool:Clone()
	yes.Parent = plr.Backpack

end)

4 comments

0

Have you made an attempt at this?

0

yes have

0

Well, did it work?

0

Is it working now?If not ill start working on the script myself and find out whats wrong.

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.