So i'm using a script that when player clicks the button that the localscipt is child to adds clothing and a mesh hat, Now the script works in studio, however when I go into game and try it spawns the hat but it isn't attached to the character. Any help is well appreciated, here's the code for reference.

function click()
	--Shirt&Pants
	shirt = nil
	pants = nil
	player = script.Parent.Parent.Parent.Parent.Parent
	playername = player.Name
	character = game.Workspace:FindFirstChild(playername)
	children = character:GetChildren()
	for i = 1, #children do
		if children[i].ClassName == "Shirt" then
			print("shirt found")
			shirt = children[i]
		end
		if children[i].ClassName == "Pants" then
			print("pants found")
			pants = children[i]
		end
	end
	if shirt ~= nil then
		print("shirt destroyed")
		shirt:Destroy()
	end
	print("shirt created")
	shirt = Instance.new("Shirt")
	shirt.Parent = character
	shirt.Name = "Shirt"
	shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=232609207"
	
	if pants ~= nil then
		print("pants destroyed")
		pants:Destroy()
	end
	print("pants created")
	pants = Instance.new("Pants")
	pants.Parent = character
	pants.Name = "Pants"
	pants.PantsTemplate = "http://www.roblox.com/asset/?id=232607587"
	
	--Shirt&Pants End
	--Hat starts
	hat = Instance.new("Hat")
	part = Instance.new("Part")
	hat.Name = "Basic Legionaire"
	part.Parent = hat
	part.Position = character:FindFirstChild("Head").Position
	part.Name = "Handle"
	part.formFactor = 0
	part.Size = Vector3.new(1, 1, 1) 
	part.BottomSurface = 0 
	part.TopSurface = 0 
	part.Transparency=0
	part.Locked = true 
	game.Lighting.meshes.Ranker1:Clone().Parent = part
	hat.Parent = character
	hat.AttachmentPos = Vector3.new(0,-.7,0.1)
end

script.Parent.MouseButton1Click:connect(click)

1 comment

0

Lighting should NOT be used as storage. And FormFactor and connect are deprecated use Connect instead, FormFactor is just deprecated. Instead of using crap ton of parents just use LocalPlayer!