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

How to detect if this variable is in-game?

local Owner = game.Players.ImKittenOuttaMyMind

if --How would I detect for the variable "Owner" to be in the game?
	
end

1 answer

✓ Accepted answer

Accessing a child that doesn't exist will throw an error.

We can use FindFirstChild to solve this problem, since instead of throwing an error, it just returns nil if the child is not present.

if game.Players:FindFirstChild("ImKittenOuttaMyMind") then
	-- nil is falsey, so if they are not present, this is fault
	-- all other objects are truey, so if they are present,
	-- this will occur:
	-- At this instant, ImKittenOuttaMyMind is a child of Players
end

1 comment

0

Thanks! I'm used to scripting in Java, so Lua is a bit confusing!

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