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