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

Why does this script not detect when a player has a blue head?

I'm trying to make a script to check when a new player joins so it can prompt them with instructions. I have a script which changes there head to the color bright blue, and all the colors for a noob.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		
		local head = game.Workspace:WaitForChild(player.Name).Head
		
		wait(0.5)
		
		if head.BrickColor == "Bright blue" then
			print(player.Name.." is a noob!")
		else
			print("Not a noob")
		end
	end)
end)

My script prints "Not a noob" but my head color is Bright blue. Anyway to fix this?

1 comment

0

You need to use the BrickColor.new() constructor: if head.BrickColor == BrickColor.new("Bright blue") then

1 answer

You're comparing a string to a userdata.

This will always result in false. What you can do is compare the name of the BrickColor to "Bright blue".

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        print(player, character.Head.BrickColor.Name == "Bright blue" and "Is a noob" or "Not a noob")
    end)
end)

A few changes

  • Used the character variable. It's unreliable to get the character from workspace since a player could have the same name as something in the workspace like Terrain.
  • Used :GetService(). This is the canonical way to get services. :GetService() gets a service by class name, as opposed to by name.
  • Removed the control structures in place of a "ternary". If the brick color name is bright blue, character.Head.BrickColor.Name == "Bright blue" and "Is a noob" or "Not a noob" evaluates to "Is a noob", otherwise will evalúate to "Not a noob" because they are not bright blue

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