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
8 years ago
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.

2 answers

Log in to vote
1
Answered by
w00t111 10
8 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'

-- 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
0
didn't work after I tried it Akozta 40 — 8y
0
That's weird... when I debugged it in studio with 'player=workspace.Player1'' it worked.... w00t111 10 — 8y
Ad
Log in to vote
1
Answered by
Vezious 310 Moderation Voter
8 years ago

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)

Answer this question