Hat giver in GUI

,

Hello. I am trying to make a button that gives you a hat when you click it. I have made a script wich you can see here;

local plr = game.Players.LocalPlayer
local char = plr.Character
local hat = script.Parent:FindFirstChild("hat")


script.Parent.MouseButton1Click:Connect(function()
	local clone = hat:Clone()
	local weld = Instance.new("WeldConstraint")
	weld.Parent = hat
	weld.Part0 = hat
	weld.Part1 = char.Head
	clone.Anchored = false
end)

but it doesn’t work. I don’t know what I’m doing wrong. This is how my stuff is set up in the explorer
image

If you need any other details please let me know. Thank you.

1 Like

note: i have added the hat to the head and it still doesn’t work

It’s a LocalScript, so the hat only shows locally.

new script(forgot to actually asign it to the head)
image
but it still doesnt sit right on the head…

1 Like

how would i make it serverside hat give via gui

RemoteEvents.

button → send to server → adds accessory

Confusing. Can you perhaps give me an example?


CLIENT:

local button = script.Parent
local remoteevent = -- path to remote event, must be in replicatedstorage
button.MouseButton1Click:Connect(function()
    remoteevent:FireServer()
end)

SERVER:

local remoteevent = -- path to remote event, must be in replicatedstorage

remotevent.OnServerEvent:Connect(function(player)
    local newhat = hatthing:Clone()
    -- all the other stuff

   newhat.Parent = player.Character:FindFirstChild("Head")
end)
1 Like

That mostly worked. But how do I get the hat on top of the playuers head?
image

I made it work.
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.