1 | script.Parent.MouseButton 1 Down:connect( function () |
2 | playername = script.Parent.Parent.Parent.Parent.Name |
3 | player = Workspace:FindFirstChild( "" ..playername.. "" ) |
4 | if player ~ = nil then |
5 | player:FindFirstChild( "Shirt" ).ShirtTemplate = "http://www.roblox.com/asset/?id=14729308" |
6 | end |
7 | 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'
01 | -- First lets remove the old hats! |
02 | for i,v in pairs (player:GetChildren()) do -- Lets get the Player's Characters Children! |
03 | if v:IsA( "Hat" ) then -- Beep beep beep, we found one! |
04 | ypcall( function () -- Why not have some protection? |
05 | v:Destroy() -- Boom, hat is gone! |
06 | end ) -- end for ypcall |
07 | end -- end for if statement |
08 | end -- end for searching Characters children |
09 |
10 | -- Now we need the hats you want to give to the player! |
11 | local AssetIds = { 306968119 , 150381051 } -- Put the hat asset ids into here, I put two example ids in |
12 | for i,v in pairs (AssetIds) do -- Going through table |
13 | game:GetService( "InsertService" ):LoadAsset(v):GetChildren() [ 1 ] .Parent = player -- Inserting hat and parenting to Players character |
14 | end -- End for going through AssetIds table |
I know you didn't come to fix that code you gave us, but, here you go.
1 | script.Parent.MouseButton 1 Down:connect( function (Player) |
2 | Character = Player.Character |
3 | if Character ~ = nil then |
4 | Character:FindFirstChild( "Shirt" ).ShirtTemplate = "http://www.roblox.com/asset/?id=14729308" |
5 | end |
6 | end ) |