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

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

Asked by 5 years ago

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

Log in to vote
-1
Answered by
clc02 553 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
Dang forgot about that. Thanks! JJBIoxxer 50 — 5y
0
Is it possible to make the game go back and choose another color when the player resets or dies? JJBIoxxer 50 — 5y
0
Updated the answer clc02 553 — 5y
0
Thanks JJBIoxxer 50 — 5y
Ad

Answer this question