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 a player has a certain child?

I am trying to make a ban script but i don't know how to check if a player has a certain child without the script outputting an error

Code:


game.Players.PlayerAdded:Connect(function(player)
	for _, v in pairs(game.Players:GetPlayers(player)) do
		local bool = Instance.new("BoolValue")
		bool.Name = ("Banned_" ..player.UserId)
		bool.Parent = player
		break
	end
end)

2 answers

FindFirstChild is your friend here.

FindFirstChild will return true if the Instance exists or false if it does not.

e.g. if you wanted to check whether a Model called "Test" exists you would do:

print(workspace:FindFirstChild("Test"))

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