Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
imaA6D 39
4 years ago

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

0
game.Players['3KingsOfEgypt'].Character.HumanoidRootPart.Anchored = true Azarth 3141 — 4y
0
Maybe, you should use local player. Block_manvn 395 — 4y
0
@Block_manvn i already know that imaA6D 39 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

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

0
Thanks imaA6D 39 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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.

0
Thanks imaA6D 39 — 4y
Log in to vote
0
Answered by 4 years ago

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

game.Players["playernamehere"].Character.HumanoidRootPart.Anchored = true
0
Ty imaA6D 39 — 4y

Answer this question