Tutorial:Working Hat Giver | Roblox Wiki - Fandom

Tutorial pageThis article is an intermediate tutorial.All tutorials · Scripting tutorials

Hello! This very quick tutorial will teach you how to make a working hat giver in Roblox Studio.

Before we begin, although this is an intermediate tutorial, you should have knowledge of everything from the Advanced Guide to Scripting.

Contents

  • 1 Accessing the Hat
    • 1.1 From Toolbox
    • 1.2 From Scratch
    • 1.3 From the Marketplace
  • 2 Coding the Hat Giver

Accessing the Hat[]

Firstly, you need to access the hat.

From Toolbox[]

If you use a free model from the Toolbox, it should already be placed in a model. One specific part has to be named "Handle," just like a Tool. Then put it into ServerStorage.

From Scratch[]

If you model a hat from scratch, one part needs to be named Handle. I will not get much into detail about modelling the hat. Again, place it into ServerStorage.

From the Marketplace[]

There are a lot of great hats in the Roblox Marketplace. If you wish to use one from there, copy the AssetId.

Then, in Roblox Studio, if you do not have a command bar at the bottom of your screen, insert it using a View Tab. Then, type the following into the command bar:

game:GetService("InsertService"):LoadAsset(XXXXXXXXXX).Parent = game.ServerStorage

Replace XXXXXXXXXX with the AssetId. Now, there should be a model in ServerStorage. Best rename it to prevent any confusion.

Coding the Hat Giver[]

Now, insert a part into the Workspace. This will be your giver. You can model it as much as you want, but this is not a building tutorial. Insert a script into the Part.

First, we set up a Touched event:

script.Parent.Touched:Connect(function(hit) end)

Now, we need to check for the Humanoid, to see if the object that fired the event is human.

script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then end end)

Finally, we clone the hat and parent it to the player's character.

script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then local hat = game.ServerStorage.Hat:Clone() hat.Parent = hit.Parent end end)

So, when a player touches the part, the hat will be cloned and parented to the player's character.

Tag » How To Make Hats On Roblox