Help with making a tool that equips a hat when you click

  1. What do you want to achieve?
    I want to make a Tool that equips a hat when you click
  2. What is the issue?
    I can’t seem to find any tutorials on how to do this
  3. What solutions have you tried so far?
    Searched the devforum, youtube, Scriptinghelpers, Etc.

I even tried making a script of my own (it didn’t go so well)

here’s the script:

local Tool = script.Parent
debounce = true

function onTouched(hit)
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
if (hit.Parent:findFirstChild(“Humanoid”) ~= nil and debounce == true) then
debounce = false
h = Instance.new(“Hat”)
p = Instance.new(“Part”)
h.Name = “GreenTopHat”
p.Parent = h
p.Position = hit.Parent:findFirstChild(“Head”).Position
p.Name = “Handle”
p.formFactor = 0
p.Size = Vector3.new(0,-0.25,0)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
script.Parent.Mesh:clone().Parent = p
h.Parent = hit.Parent
h.AttachmentPos = Vector3.new(0,0.15,0)
wait(5)
debounce = true
end
script.Parent.Touched:connect(onTouched)
end)
end)

end


Does anyone know how to do this?

4 Likes

Just create a hat and put it into ServerStrorage, and script it for its clones the hat to inside of player. Do not try to create a hat by script, that’s will need more effort. (Note: do not inside player head, inside character)

1 Like

Thanks For Replying! I’ll Give It A Try.

1 Like

@Seuika
So this is what I have so far

image

image

image
(this is the code inside the hatgiver)

This didn’t end up giving the StarterCharacter The hat. Did I do something wrong?

Edit: I just realised I made the hat in serverstorage “NightVisionGoggles” but in the script i put “HairAccessory.” However, Even after I fixed the mistake it still didn’t work.

It working (Copying from ServerStorage) perfectly on me.
Try my tool example i created for you (I will delete that after my solution worked)

Problem in your script is game.StarterPlayer is doesn’t able to give you localplayer. You should use RemoteEvent for creating tools like that! Note: “ServerStorage.a” is hat i used to create example.

1 Like

Thanks For letting me look at that code! It Worked.

Edit: Forgot to say you can delete the tool now

Thank you, I needed it too!

1 Like