I am trying to make a script that will unanchore every players humanoid rootpart on a NumberValue changed. The problem is I dont know how to refer to a players character.
✓ ANSWER ACCEPTED
How do i reference every players character?
1 answer
✓ Accepted answer
To get a players character
Client
Player, starter pack and player gui
game.Players.LocalPlayer:WaitForChild("Character")
Server
ServerScriptService and workspace
--When a player is added, works on client too but might not in workspace
game.Players.PlayerAdded:Connect(function(player)
--Action
end)
--or, this uses touched event since there is no other way
local players = game:GetService("Players")
part.Touched:Connect(function(hit)
local player =players:GetPlayerFromCharacter(hit.Parent)
end)
1 comment
0
Yeah don't do game.Players.LocalPlayer:WaitForChild("Character"). That's going to infinite yield Character isn't a child of the Player it's a property. Anyway, just use StarterCharacterScripts and game.Players.LocalPlayer.Character.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Even though this is answered, please include the code you are working with next time.