function OnClick() local players = game.Players:GetPlayers() for i=1,#players do if (players[i]:FindFirstChild("leaderstats") ~= nil) then local clicks = players[i]:FindFirstChild("leaderstats")["ParkBucks"] if (clicks ~= nil) then script.Parent.ClickDetector.MaxActivationDistance = 0 script.Parent.Transparency = 1 clicks.Value = clicks.Value + 10 script.Parent.Sound:Play() wait(20) script.Parent.ClickDetector.MaxActivationDistance = 10 script.Parent.Transparency = 0 end end end end script.Parent.ClickDetector.MouseClick:connect(OnClick)
I do not know what is wrong with my script, when it regenerates it gives the previous player that clicked it the money instead of the "clicker". Any help will be greatly appreciated.
Instead of looping through game.Players, you can use the player parameter of MouseClick
script.Parent.MouseClick:Connect(function(playerWhoClicked) local leaderstats = playerWhoClicked:FindFirstChild("leaderstats") if leaderstats then local clicks = leaderstats.Clicks script.Parent.ClickDetector.MaxActivationDistance = 0 script.Parent.Transparency = 1 clicks.Value = clicks.Value + 10 script.Parent.Sound:Play() wait(20) script.Parent.ClickDetector.MaxActivationDistance = 10 script.Parent.Transparency = 0 end end)