Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix this game.Players function thing? (please help i am beginner)

Hello, im trying to make a anchor player thing for something in my studio, and when i put name in the "NAME" area it works. But when there is number in front of it, it doesn't work and there is a red line. How do i fix? (Sorry for bad english and im also not good at verbally explaining stuff and sorry for the very small image down below)

original code: game.Players.NAME.Character.HumanoidRootPart.Anchored = true

edited code (using a friends name): game.Players.3KingsOfEgypt.Character.HumanoidRootPart.Anchored = true

image: https://imgur.com/JYIanFW

3 comments

0

game.Players['3KingsOfEgypt'].Character.HumanoidRootPart.Anchored = true

0

Maybe, you should use local player.

0

@Block_manvn i already know that

3 answers

✓ Accepted answer

Use :FindFirstChild() for player name, here is the fixed code:

game.Players:FindFirstChild("NAME").Character.HumanoidRootPart.Anchored = true

This will work even with numbers in a player's name

1 comment

0

Thanks

local plr_name = game.Players.USERNAME

local plr = game.Workspace:FindFirstChild(plr_name)

plr.Character.HumanoidRootPart.Anchored = true

Kinda the same the script as Lord_WitherAlt's one.

1 comment

0

Thanks

Here's another way to do it because why not.

game.Players["playernamehere"].Character.HumanoidRootPart.Anchored = true

1 comment

0

Ty

This discussion is preserved as it was. New answers, comments, and votes are closed.