Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this script work for hats?

Asked by
Akozta 40
9 years ago
1script.Parent.MouseButton1Down:connect(function()
2playername = script.Parent.Parent.Parent.Parent.Name
3player = Workspace:FindFirstChild(""..playername.."")
4if player ~= nil then
5  player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=14729308"
6end
7end)

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.

2 answers

Log in to vote
1
Answered by
w00t111 10
9 years ago

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!
02for 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
08end -- end for searching Characters children
09 
10-- Now we need the hats you want to give to the player!
11local AssetIds = {306968119,150381051} -- Put the hat asset ids into here, I put two example ids in
12for 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
14end -- End for going through AssetIds table
0
didn't work after I tried it Akozta 40 — 9y
0
That's weird... when I debugged it in studio with 'player=workspace.Player1'' it worked.... w00t111 10 — 9y
Ad
Log in to vote
1
Answered by
Vezious 310 Moderation Voter
9 years ago

I know you didn't come to fix that code you gave us, but, here you go.

1script.Parent.MouseButton1Down:connect(function(Player)
2Character = Player.Character
3if Character ~= nil then
4Character:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=14729308"
5end
6end)

Answer this question