I want to make a script that only adds a stat to the player who clicked the part once and can't be clicked over and over again. Is there a way for it to be player specific and doesn't effect the entire servers ability to click it?
Here is the code I have:
script.Parent.ClickDetector.MouseClick:connect(function(player) local players = game.Players:FindFirstChild(player.Name) local stat = players:FindFirstChild("leaderstats")["Kirbies Found"] stat.Value = stat.Value + 1 end)
To prevent multiple people from clicking/touching/activating the same object multiple times, you can make use of a debounce table. Since the first parameter of MouseClick is the player instance that clicked the part then you don't really have to use :FindFirstChild()
on the Players service.
local Debounce = {} script.Parent.ClickDetector.MouseClick:Connect(function(player) --Return immediately if the player has clicked the block. if Debounce[player] then return end --If they haven't clicked the block then put them on the table. Debounce[player] = true local stat = player:WaitForChild("leaderstats")["Kirbies Found"] stat.Value = stat.Value + 1 end)
Please accept this answer if it helps.