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 9 years ago

I tried doing:

local hh = hit.Parent.Name
game.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 — 9y

2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 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.

local variable = 'Player'

if game.Players:FindFirstChild(variale) then
    print('isPlayer')
else
    print('no')
end
0
Thanks! That was the solution to my problem! Vill1234 15 — 9y
0
Yup, if you wouldn't mind, do please accept my answer by clicking the "accept answer" button located to the right ImageLabel 1541 — 9y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 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"].

game.Workspace

-- same as
game["Workspace"]

-- or the same as
serviceName = "Workspace"
game[serviceName]

Answer this question