Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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?

0
You need to use the `BrickColor.new()` constructor: `if head.BrickColor == BrickColor.new("Bright blue") then` LukeSmasher 619 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
Ad

Answer this question