How to make a certain player have a certain hat when joined

Hi there, I am Crrustyy. I was wondering how to make it where a specific player (e.g Crrustyy) has a certain hat (e.g domino crown) when they join. How can this be accomplished?

Many thanks,

Crrustyy

4 Likes

You could either have a premade accessory stored in Replicated/ServerStorage and clone it in player’s character once their character is added to the game or use HumanoidDescription and apply it to their humanoid once their character is added the game.
In order to have hats for specific players only, you can do this

local users = {
    00000000 --replace with your user id
}

local isAllowed = function(player, tab)
    for i, v in pairs(tab) do
        if player.UserId == v then return true end
    end
    return false
end

This function will basically check if player’s UserId matches any UserId from the table and return either true or false. Now all you have to do it call that function.

7 Likes

Thank you! How/Where should I put the item Id?

2 Likes

Are you using HumanoidDescription or pre-made accessory?

2 Likes

I am using an item from the catalog, i want it to be assigned to a certain player, e.g me

2 Likes

Okay so, first run those two lines of code in your command bar in order to get the accessory

local id = 000000 --replace with your accessory id 
game:GetService("InsertService"):LoadAsset(id).Parent = workspace
4 Likes

where would I start scripting this? In character scripts?

3 Likes


Command bar, at the bottom of your screen

4 Likes

Ah yes, sorry, I didn’t see that. Is this whilst I’m playing?

3 Likes

It doesn’t really matter whether you’re playing or not, it’ll work either way

5 Likes

Ok, I’ve entered it in. The text just gets highlighted in blue. Is this meant to happen?

3 Likes

Never mind, checked the output and the hat has appeared, what’s next?

3 Likes

Okay so, once you enter this in your command bar, press Enter key on your keyboard and it’ll be added to workspace. After that’s done, go to workspace and drag the accessory to ServerStorage.
Note: accessory will be parented to a model once it’s added make sure to only use accessory without the model.

5 Likes

I have dragged the little ‘wizard hat’ icon into the server storage, what’s next?

3 Likes

Now the final step is to add this code to a script which is located in ServerScriptService

local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")

local users = {
    28373405 --replace with your user id
}

local isAllowed = function(player, tab)
    for i, v in pairs(tab) do
        if player.UserId == v then return true end
    end
    return false
end

players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		local hat = serverStorage:WaitForChild("Hat") --make sure to enter your hat's name
		if isAllowed(player, users) then
			local clone = hat:Clone()
			clone.Parent = character
		end
	end)
	
end)

Once you’re done with that, you should spawn with wanted hat. :+1:

13 Likes

Thank you! It was easier with a walkthrough tutorial rather than a chunk of info. You really helped!

4 Likes

I’m glad I was able to help you there!

10 Likes

What if i want to give all players the hat??

3 Likes

It would be similar to the code above but instead:

So as he did, to get the accessory using InsertService

local id = yourid
game:GetService("InsertService"):LoadAsset(id).Parent = workspace

Then after this create a new Script in ServerScriptService then paste this script!

local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")

players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character)
		local hat = serverStorage:WaitForChild("Hat") -- hat name in serverstorage
			local clone = hat:Clone()
			clone.Parent = character
 end)
end)

Make sure not to drag the model into ServerStorage instead drag the accessory inside the model into server storage and name it “Hat”.

It should look like this:
image

Hope this helps!

1 Like