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

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

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?

1 comment

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.

2 answers

✓ Accepted answer

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

2 comments

0

Thanks! That was the solution to my problem!

0

Yup, if you wouldn't mind, do please accept my answer by clicking the "accept answer" button located to the right

: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]

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