Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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!

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.... greatneil80 2647 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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)

0
accept answer btw creeperhunter76 554 — 6y
0
Thankyou dude, this worked! Goldenkings11 -11 — 6y
Ad

Answer this question