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
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
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.
Thank you! How/Where should I put the item Id?
Are you using HumanoidDescription or pre-made accessory?
I am using an item from the catalog, i want it to be assigned to a certain player, e.g me
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
where would I start scripting this? In character scripts?
Ah yes, sorry, I didn’t see that. Is this whilst I’m playing?
It doesn’t really matter whether you’re playing or not, it’ll work either way
Ok, I’ve entered it in. The text just gets highlighted in blue. Is this meant to happen?
Never mind, checked the output and the hat has appeared, what’s next?
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.
I have dragged the little ‘wizard hat’ icon into the server storage, what’s next?
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.
Thank you! It was easier with a walkthrough tutorial rather than a chunk of info. You really helped!
I’m glad I was able to help you there!
What if i want to give all players the hat??
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:
Hope this helps!