How would I make a Hat giver using an ID given by the user?

Good luck. Also an important thing to note (which I initially struggled with) is the parameters of the FireServer() and OnServerEvent functions. The first parameter of the OnServerEvent will be the player executing the script by default, while the second parameter will be the first of the FireServer(). So when assigning the hat, the ServerScript would look something like:

local Remote = game:GetService("ReplicatedStorage").HatRemote --Add the RemoteEvent "HatRemote" in first.
Remote.OnServerEvent:Connect(function(player,ID)
   local accessory = game:GetService("InsertService"):LoadAsset(ID):GetChildren()
    for i,v in pairs(accessory) do 
        accessory.Parent = player.Character
    end
end)

And the LocalScript in the Gui will be something like:

local Remote = game:GetService("ReplicatedStorage").HatRemote
script.Parent.MouseButton1Click:Connect(function()
    local ID = tonumber(script.Parent.Text) --Reference to the text inputted.
    Remote:FireServer(ID)
end)
1 Like

One more thing to note, make sure you add sanity checks in case an exploiter spams the RemoteEvent to lag the server out or uses it for themselves.

1 Like

I’ve used your script to help me do this, and it worked! Thanks everyone for your help and I hope that I didn’t waste anyones time today!

1 Like