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

Why doesn't this work? Part 2

math.randomseed(tick())

local skinT = {"125", "1030", "18"}

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character

local bColors = character:WaitForChild("Body Colors")

local newskin = skinT[math.random(1,3)]     

bColors.HeadColor = BrickColor.new(newskin)
bColors.LeftArmColor = BrickColor.new(newskin)
bColors.RightArmColor = BrickColor.new(newskin)
bColors.TorsoColor = BrickColor.new(newskin)
bColors.LeftLegColor = BrickColor.new(newskin)
bColors.RightLegColor = BrickColor.new(newskin)
local shirt = character:WaitForChild(Shirt)
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=167295776"
local pant = character:WaitForChild(Pants)
pant.PantsTemplate = "http://www.roblox.com/asset/?id=112052973"
local head = character:WaitForChild(Head1)
head.BrickColor = BrickColor.new(newskin)

Same thing as before, but now the skin colors work. The problem now is that the shirt, pants, and the head won't change to what I want it to. When it does work, it doesn't work all the time.

1 answer

✓ Accepted answer

The argument of WaitForChild needs to be a string. Also, not everyone is going to have shirts and pants, so you need to deal with that.

In this case, the scripts makes a new shirt and pants. Then, in a new thread, the script waits for the old clothing to be added, then destroys it. A new thread is necessary so the script doesn't get stuck waiting for clothing to be added.

math.randomseed(tick())

local skinT = {"125", "1030", "18"}

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character

local bColors = character:WaitForChild("Body Colors")

local newskin = skinT[math.random(1,3)]     

bColors.HeadColor = BrickColor.new(newskin)
bColors.LeftArmColor = BrickColor.new(newskin)
bColors.RightArmColor = BrickColor.new(newskin)
bColors.TorsoColor = BrickColor.new(newskin)
bColors.LeftLegColor = BrickColor.new(newskin)
bColors.RightLegColor = BrickColor.new(newskin)

local shirt = Instance.new("Shirt",character)
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=167295776"
shirt.Name = "NewShirt"
coroutine.wrap(function()
character:WaitForChild("Shirt"):Destroy()
end)()

local pant = Instance.new("Pants",character)
pant.PantsTemplate = "http://www.roblox.com/asset/?id=112052973"
pant.Name = "NewPants"
coroutine.wrap(function()
character:WaitForChild("Pants"):Destroy()
end)()

local head = character:WaitForChild("Head")
head.BrickColor = BrickColor.new(newskin)

7 comments

0

It works except the pants

0

I tested it myself and the pants work. I'm not sure what you're doing differently.

0

I don't know the head is having the porblem too

0

Can you be more specific about what the problem is?

0

So when I go to Play Solo, The shirt comes up, but not the Pants, and the head isn't being the color I want it to.

0

Any errors?

0

No, but I fixed the Pants now, Now I just need the head.

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