✓ Accepted answer
In ROBLOX, the player loads before the character. With this knowledge, you need a way to wait until the character is available before anchoring their torso.. There are two methods I recommend for you to use and they vary depending on what you want to do.
For each of my methods, you may need to use WaitForChild. WaitForChild essentially waits until the child specified is available. This causes less errors but if the child is never added in, the script will yield (wait) forever, not returning an error and causing confusion when debugging your code.
Method 1:
If you want the script to only work when the player first joins the server, you can use the CharacterAdded event and the wait function of an event. The wait function is similar to wait(), but instead of waiting for a certain amount of time before continuing on with the rest of the code, it waits until the event you called it on has fired.
If you chose the first method, your script should look like this:
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.CharacterAdded:wait()
newPlayer.Character:WaitForChild("Torso").Anchored = true
end)
Method 2:
If you want the script to work each time the player spawns in, you need to make another function similar to line 1 which use newPlayer.CharacterAdded instead of game.Players.PlayerAdded. You will need another end with a parenthesis around it if you choose to do this.
If you chose the second method, your script should look like this:
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.CharacterAdded:connect(function(char)
char:WaitForChild("Torso").Anchored = true
end)
end)
I hope my answer helped you. If it did, be sure to accept it.