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!
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)