I'm trying to make a tool which gives a player a hat, shirt and pants.I don't have any error the only reason I'm asking this question is because the hat is invisible and I can see it only after I press = but it's already dropped and I clearly don't want this.Hre's the "Hat" section of the script
for i, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Hat") and v.Name == "Duh" then v:Clone().Parent = Char v:Clone().Handle.Position = Char.Head.Position v:Clone().AttachmentForward = Vector3.new(-0, -0.197, -0.98) v:Clone().AttachmentPos = Vector3.new(0, -0.35, 0) v:Clone().AttachmentRight = Vector3.new(1, -0, 0) v:Clone().AttachmentUp = Vector3.new(0, 0.98, -0.197) end end
Simple. You are calling Clone()
function 6 times, so you'll get 6 hats. And every one is misconfigured.
for i, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Hat") and v.Name == "Duh" then v:Clone().Parent = Char -- copies an hat and parents it to the player v:Clone().Handle.Position = Char.Head.Position -- copies an second hat and puts it on player, but no parent v:Clone().AttachmentForward = Vector3.new(-0, -0.197, -0.98) -- third hat v:Clone().AttachmentPos = Vector3.new(0, -0.35, 0) -- fourth hat v:Clone().AttachmentRight = Vector3.new(1, -0, 0) -- fifth hat v:Clone().AttachmentUp = Vector3.new(0, 0.98, -0.197) --sixth hat end end
To solve this problem, we should use a variable, once Clone()
function returns the copied object.
for i, v in pairs(game.Workspace:GetChildren()) do if v:IsA("Hat") and v.Name == "Duh" then local hat = v:Clone() -- copies the hat and returns it. Now, hat is the hat! hat.Parent = Char -- parents the copied hat hat.Handle.Position = Char.Head.Position -- puts it on player hat.AttachmentForward = Vector3.new(-0, -0.197, -0.98) -- stuff hat.AttachmentPos = Vector3.new(0, -0.35, 0) -- hat stuff hat.AttachmentRight = Vector3.new(1, -0, 0) -- more hat stuff hat.AttachmentUp = Vector3.new(0, 0.98, -0.197) --even more hat stuff end end
Hope I helped! :)