Ad
Log in to vote
0

I am trying to make a random colored head but it doesn't work?

Asked by 1 year ago

I'm trying to make it so when the user joins, they will have a random colored head. Here's my script

local Player = game:GetService("Players")
Player.PlayerAdded:Connect(function(player)
    player.Character.Head.BrickColor = BrickColor.Random()
end)

2 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

There is a typo on line 3, do this instead:

player.Character.Head.BrickColor = BrickColor.random()

remember that function calls are case-sensitive

edit: you should also do this every time the player's character is added because as it stands it will do one of two things:

  • give an error because the player is added before the character is
  • if the character exists, this will only happen once and if the person dies, resets their character, etc. their head will go back to normal

so try this:

local Player = game:GetService("Players")
Player.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
    character.Head.BrickColor = BrickColor.random()
    end)
end)
0
it still doesn't work. It's a localscript in ServerScriptService. CountOnMeBro 51 — 1y
0
LocalScripts run on the client side and do not work under ServerScriptService. Put this in a regular (server-side) script. You should use Scripts for things you want everyone in the game to see (so, most things), and LocalScripts are mainly for GUIs and other things that are unique to each person OfficerBrah 494 — 1y
0
i put a script in ServerScriptService and it still doesnt work CountOnMeBro 51 — 1y
0
I tested this in Studio and it works when you put wait() before line 4, so I guess Roblox overrides the head's color when the character is initially created and that's why it doesn't work without the wait() OfficerBrah 494 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

You need the BodyColor:

local Char = game.Players.LocalPlayer.Character
local BodyColors = Char:WaitForChild("BodyColors")

wait(0.1)
BodyColor.Head.BrickColor = BrickColor.random()
0
thanks to you both!!! CountOnMeBro 51 — 1y

Answer this question