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

Why am I getting an error when running my torso color script?

When press play to test my script I get an error on line 6. Not sure what's wrong :/


torso = game.StarterPlayer.StarterCharacter.Torso
playercolor = math.random(1,5)
if playercolor == 1 then
	torso.BrickColor = Color3.fromRGB(242, 243, 243)
end
elseif playercolor == 2 then
	torso.BrickColor = Color3.fromRGB(196, 40, 28)
end
elseif playercolor == 3 then
	torso.BrickColor = Color3.fromRGB(40, 127, 71)
end
elseif playercolor == 4 then
	torso.BrickColor = Color3.fromRGB(27, 42, 53)
end
else
	torso.BrickColor = Color3.fromRGB(99, 95, 98)
end

1 answer

✓ Accepted answer

You only need one end for a set of if/elseif/else conditionals. elseif acts as the end for the if on line 3.

Per the comment: Yes, just wrap it in a function within the player.CharacterAdded event like so:

game.Players.PlayerAdded:Connect(function(p)
  p.CharacterAdded:Connect(function (c)
    torso = c.Torso
    playercolor = math.random(1,5)
    if playercolor == 1 then
      torso.BrickColor = Color3.fromRGB(242, 243, 243)
    elseif playercolor == 2 then
      torso.BrickColor = Color3.fromRGB(196, 40, 28)
    elseif playercolor == 3 then
      torso.BrickColor = Color3.fromRGB(40, 127, 71)
    elseif playercolor == 4 then
      torso.BrickColor = Color3.fromRGB(27, 42, 53)
    else
      torso.BrickColor = Color3.fromRGB(99, 95, 98)
    end
  end)
end)

4 comments

0

Dang forgot about that. Thanks!

0

Is it possible to make the game go back and choose another color when the player resets or dies?

0

Updated the answer

0

Thanks

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