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

Why doesn't this work? Part 2

Asked by 9 years ago
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

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
9 years ago

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)
0
It works except the pants PancakeChop 35 — 9y
0
I tested it myself and the pants work. I'm not sure what you're doing differently. 2eggnog 981 — 9y
0
I don't know the head is having the porblem too PancakeChop 35 — 9y
0
Can you be more specific about what the problem is? 2eggnog 981 — 9y
View all comments (3 more)
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. PancakeChop 35 — 9y
0
Any errors? 2eggnog 981 — 9y
0
No, but I fixed the Pants now, Now I just need the head. PancakeChop 35 — 9y
Ad

Answer this question