script.Parent.MouseButton1Down:connect(function() playername = script.Parent.Parent.Parent.Parent.Name player = Workspace:FindFirstChild(""..playername.."") if player ~= nil then player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=14729308" end end)
I'm a beginner scripter, so it took me forever just to make this script for shirts, but I can't figure out ow to convert this to hats. Please help.
I'm going to ignore how inconvenient your code is because I'll spend hours rambling,
What you could do for example, put in-between your if statements for 'player~=nil'
-- First lets remove the old hats! for i,v in pairs(player:GetChildren()) do -- Lets get the Player's Characters Children! if v:IsA("Hat") then -- Beep beep beep, we found one! ypcall(function() -- Why not have some protection? v:Destroy() -- Boom, hat is gone! end) -- end for ypcall end -- end for if statement end -- end for searching Characters children -- Now we need the hats you want to give to the player! local AssetIds = {306968119,150381051} -- Put the hat asset ids into here, I put two example ids in for i,v in pairs(AssetIds) do -- Going through table game:GetService("InsertService"):LoadAsset(v):GetChildren()[1].Parent = player -- Inserting hat and parenting to Players character end -- End for going through AssetIds table
I know you didn't come to fix that code you gave us, but, here you go.
script.Parent.MouseButton1Down:connect(function(Player) Character = Player.Character if Character ~= nil then Character:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=14729308" end end)