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

How come my hat team script giver doesn't work?

Asked by 9 years ago

So, I made a script in which it gives uniforms to the teams, and a hat. The uniforms clothing shirts and pants show up and work fine, but the hats don't show up. I placed a hat object into Lighting then I placed the model of the hat as it's child. How can I fix the problem in which the hat doesn't show up?

local team1 = game.Teams:findFirstChild("Germans")
local team2 = game.Teams:findFirstChild("U.S. Army") 
--                           put the team name, not color
local t1shirt = game.Lighting:findFirstChild("RedShirt")
local t2shirt = game.Lighting:findFirstChild("GreenShirt")

local t1hat = game.Lighting:findFirstChild("RedHat")
local t2hat = game.Lighting:findFirstChild("GreenHat")

local t1pants = game.Lighting:findFirstChild("RedPants")
local t2pants = game.Lighting:findFirstChild("GreenPants")
--put the clothes and pants in lighting and put their name there

function onSpawn(player)

wait(1) -- takes time for the clothes to load

local clothing = player.Character:GetChildren()

for i = 1, #clothing do -- my favorite line in scripting, this is so uesful in everything

if clothing[i].className == "Pants" or clothing[i].className == "Shirt" or clothing[i].className == "Hat" then
clothing[i]:remove() -- removes the clothes of course
end

end

if player.TeamColor == team1.TeamColor then

t1shirt:Clone().Parent = player.Character
t1pants:Clone().Parent = player.Character
t1hat:Clone().Parent = player.Character -- puts uniforms into the person

end

if player.TeamColor == team2.TeamColor then

t2shirt:Clone().Parent = player.Character
t2pants:Clone().Parent = player.Character
t2hat:Clone().Parent = player.Character

end

end



function A(new) -- this function connects the player to the function above whenever the person respawns
new.Changed:connect(function(N) if N == "Character" then onSpawn(new) end end) 
end 

game.Players.ChildAdded:connect(A) 
1
On Line 52 Should be game.Players.PlayerAdded. woodengop 1134 — 9y
0
Hats are annoying, you have to weld them. After line 40, create a weld, assing part0 as the part the hat is, assign part1 as the character's head, parent the weld to the hat or head, parent the hat to the character, and set C0 to CFrame.new(0,0,0) aquathorn321 858 — 9y
0
Can you show me how? I'm kind of confused. alan3401 28 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
local team1 = game.Teams:findFirstChild("Germans")
local team2 = game.Teams:findFirstChild("U.S. Army") 
--                           put the team name, not color
local t1shirt = game.Lighting:findFirstChild("RedShirt")
local t2shirt = game.Lighting:findFirstChild("GreenShirt")

local t1hat = game.Lighting:findFirstChild("RedHat")
local t2hat = game.Lighting:findFirstChild("GreenHat")

local t1pants = game.Lighting:findFirstChild("RedPants")
local t2pants = game.Lighting:findFirstChild("GreenPants")
--put the clothes and pants in lighting and put their name there

function onSpawn(player)

wait(1) -- takes time for the clothes to load

local clothing = player.Character:GetChildren()

for i = 1, #clothing do -- my favorite line in scripting, this is so uesful in everything

if clothing[i].className == "Pants" or clothing[i].className == "Shirt" or clothing[i].className == "Hat" then
clothing[i]:remove() -- removes the clothes of course
end

end

if player.TeamColor == team1.TeamColor then

t1shirt:Clone().Parent = player.Character
t1pants:Clone().Parent = player.Character
local clone =  t1hat:Clone() 
local w = Instance.new("Weld")
w.Part0 = clone:FindFistChild("PART") -- "PART" should be the center of the hat.
w.Part1 = player.Character.Head
w.Parent = player.Character.Head
clone.Parent = player.Character
end

if player.TeamColor == team2.TeamColor then

t2shirt:Clone().Parent = player.Character
t2pants:Clone().Parent = player.Character
local clone =  t2hat:Clone() 
local w = Instance.new("Weld")
w.Part0 = clone:FindFistChild("PART") -- "PART" should be the center of the hat.
w.Part1 = player.Character.Head
w.Parent = player.Character.Head
clone.Parent = player.Character
end

end



function A(new) -- this function connects the player to the function above whenever the person respawns
new.Changed:connect(function(N) if N == "Character" then onSpawn(new) end end) 
end 

game.Players.ChildAdded:connect(A) 

0
Thank you! alan3401 28 — 9y
0
No problem aquathorn321 858 — 9y
Ad

Answer this question