So when I join my game, and touch a block it changes my leaderstats called "Level". But when I test it out with multiple people, and I touch the block. It changes all the people leaderstats to given value. How can I fix this?
game.Players.PlayerAdded:Connect(function(player) local debounce = true script.Parent.Touched:Connect(function() local plrstats = player.leaderstats.Level if debounce then debounce = false plrstats.Value = 1 wait (1) debounce = true end end) end)
Because the parameter for game.Players.PlayerAdded:Connect(function()
is player, at which the player parameter is connected to all the players who joined the game. You should base your script on the touched function, which returns individual parts that touched the part. So, your script would be:
local debounce = true script.Parent.Touched:Connect(function(partThatTouched) local humanoid = partThatTouched.Parent:FindFirstChildWhichIsA("Humanoid") --Humanoid if humanoid then --Checks for humanoid local player = game.Players:FindFirstChild(partThatTouched.Parent.Name) --Finds player local plrstats = player.leaderstats.Level if debounce then debounce = false plrstats.Value = 1 wait (1) debounce = true end end end)