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

Ok, let’s do it like this.

First things first, let’s create a RemoteEvent under our TextButton and name it “RequestAsset”.

Now let’s create a LocalScript that will fire this RemoteEvent whenever the TextButton is clicked (again, under the TextButton).

Ever since workspace.FilteringEnabled was enforced, any text the client enters into a TextBox was NOT replicated to the server. We want to send the text AND the player in question to the server so that the server knows what assetId to load and what player to load it on.
Something like this;

local RemoteEvent = script.Parent:FindFirstChildWhichIsA("RemoteEvent")
local AssetId = script.Parent.Parent:FindFirstChildWhichIsA("TextBox")

script.Parent.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer(AssetId.Text)
end)

I want you to note that I’m assuming you have the TextBox to enter the assetId into and the TextButton we want to press to get the hat is under the same ancestor.

Now let’s create our Script under the same TextButton.

First we’ll want to get the RemoteEvent the player fires;

local InsertService = game:GetService("InsertService") --We'll need this.
local RemoteEvent = script.Parent:FindFirstChildWhichIsA("RemoteEvent")

Alright, now we’ll start listening for any events;

RemoteEvent.OnServerEvent:Connect(function(player, assetId)
    local Model = InsertService:LoadAsset(assetId) --We loaded in the asset
    
    if not player.Character then
        player.CharacterAdded:Wait() --Just in case the player does not have a character yet
    end
    for h, g in pairs(Model:GetDescendants()) do
        if g:IsA("Accessory") then
            g.Parent = player.Character
        end
    end
    Model:Destroy() --Remember to destroy the Model afterwards!
end)

If you did everything correctly, it should look like this: Baseplate.rbxl (23.7 KB)

6 Likes