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

Why doesn't this script remove the players cash onClick?

I am trying to make it where when you click the part it removes your cash and continue the script. I was told many times that I shouldn't use game.Players.LocalPlayer for a part. What should I use to replace LocalPlayer because THIS SCRIPT IS IN A PART

Please Note that both ways didn't work. Please Help!

{ Way #1 | FindFirstChild }


local price = 10
local spend = game.Players:FindFirstChild('leaderstats')

script.Parent.ClickDetector.MouseClick:Connect(function(Clicks)
	if spend.Cash.Value >= price then
		spend.Cash.Value = spend.Cash.Value - price
		--Script Continues with worthless stuff...
	elseif spend.Cash.Value < price then
		spend.Cash.Value = spend.Cash.Value - 0
		--Script Continues with worthless stuff that is negative...
	end
end)

{ Way #2 | LocalPlayer }


local price = 10
local spend = game.Players.LocalPlayer.leaderstats --Changed

script.Parent.ClickDetector.MouseClick:Connect(function(Clicks)
	if spend.Cash.Value >= price then
		spend.Cash.Value = spend.Cash.Value - price
		--Script Continues with worthless stuff...
	elseif spend.Cash.Value < price then
		spend.Cash.Value = spend.Cash.Value - 0
		--Script Continues with worthless stuff that is negative...
	end
end)

Please help me figure out what to use instead of LocalPlayer to get rid of the certain players cash!

1 comment

0

XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD guess what i figured out :P i figured out you said game.Players:WaitForChild("leaderstats") XD XD LMAO, that will never work, use your brain....

1 answer

✓ Accepted answer

Whenever you call a function with an event, usually it has parameters you can use. so with the event MouseClick, it sends the player who clicked the clickdetector. So you would use:

local price = 10

script.Parent.ClickDetector.MouseClick:Connect(function(player) --this parameter is the player who clicked the clickdetector
	local ls = player:FindFirstChild("leaderstats")
	if ls.Cash.Value >= price then
        	ls.Cash.Value = spend.Cash.Value - price
	end -- the elseif is pointless unless you want something to happen when their cash is below the price
end)

2 comments

0

accept answer btw

0

Thankyou dude, this worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.