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

Problem with navigation/variables?

Ok, i don't know how to categorize this. Anyways, somewhere in my code i have:

game.Players.plr.PlayerGui.ScreenGui.Frame.Input.Text

However, plr is supposed to point to a variable. Instead, it looks for a player named "plr". Anybody know how to fix this?

3 comments

0

If this is a local script you can do LocalPlayer in place of plr. If this is a localized player value in a regular script you can do game.Players[plr.Name].PlayerGui......exetra

0

or you can do plr.PlayerGui.ScreenGui

0

Oh, thanks.

2 answers

To fix it use

game:GetService('Players')[plr.Name].PlayerGui.ScreenGui.Frame.Input.Text

Reminder : If you are using the plr as the object of the player you must use plr.Name , if you are using it as a name put it as plr , not plr.Name, Ah i forgot , if it is a LocalScript then it wont work(only if you have set the plr as the localplayer) , if you are passing a value through a remoteEvent with the value "plr" it will work(if you are using a server script).

1 comment

0

Explain better

###If your plr variable is an object, access like this:

game:GetService("Players")[plr.Name]

###But if your plr variable is a string, specifically the player's name, do this:

local plr = game:GetService("Players").LocalPlayer.Name

game:GetService("Players")[plr]

###However none would be necessary. Just make plr a reference to the Player object, without using game:GetService("Players")[plr.Name]

###Do keep in mind that LocalPlayer cannot be used in a server script. Only local scripts.

1 comment

0

you forgot plr.PlayerGui.ScreenGui under object as the plr object doesn't need to be searched through players again.

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