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

How do you put a variable inside game.Players.(variable)?

Asked by 10 years ago

I tried doing:

1local hh = hit.Parent.Name
2game.Players.hh

But it came out with an error saying that hh is not a valid member of Players. Can if so, how do I put hh into game.Players.hh?

0
The Error is telling you there is no such Child named 'hh' within the Players Service, thus the 'hh is not a valid member of Players', this can, however, be fixed by using Brackets, however, I'd recommend using 'FindFirstChild' first. TheeDeathCaster 2368 — 10y

2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
10 years ago

Using the FindFirstChild function of ROBLOX instances, you can do just what you are attempting. The function returns the player corresponding to the passed argument, or nil.

1local variable = 'Player'
2 
3if game.Players:FindFirstChild(variale) then
4    print('isPlayer')
5else
6    print('no')
7end
0
Thanks! That was the solution to my problem! Vill1234 15 — 10y
0
Yup, if you wouldn't mind, do please accept my answer by clicking the "accept answer" button located to the right ImageLabel 1541 — 10y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

:FindFirstChild is a good thing to do -- it's necessary when you aren't absolutely sure there is an object there.

It's also a useful fact that object.index is just sugar -- it's the same thing as indexing by a string; object.index is the same thing as object["index"].

1game.Workspace
2 
3-- same as
4game["Workspace"]
5 
6-- or the same as
7serviceName = "Workspace"
8game[serviceName]

Answer this question