I wanted to give players a hat when they spawn but i only want certain player(s) to get it . How I do That? (Tell me if i didn't give enough information)
COMMUNITY QUESTION
How to give certain player certain hats when they spawn?
1 answer
Your Problem can be solved using Humanoid:AddAccessory() function. First off, Get the Accessories/Hats you want Create a Folder inside [ServerStorage] now Put the Accessories in the Folder Insert a Script into [ServerScriptService] Write this Code:
local Players = game:GetService("Players")
local HatsFolder = game:GetService("ServerStorage"):WaitForChild('FOLDERNAME') -- i'm pretty sure you can fix this for your own.
local VIP = {'ROBLOX','BuilderMan','Shedletsky'} --Replace The Strings with the players who will get the Hats, you can Add multiple Players to this Table
Players.PlayerAdded:Connect(function(p) -- 'p' is the player who just joined
for i,v in pairs(VIP) do
if p.Name == v then
p.CharacterAdded:Connect(function(char) --Fires when the Character Spawns/Respawns
wait(1)
local Humanoid = char:WaitForChild('Humanoid')
for _,hat in pairs(HatsFolder:GetChildren()) do wait() --yeah.
if hat:IsA('Accessory') or hat:IsA('Accoutrement') or hat:IsA('Hat') then --Checks if the Instance is a Hat/Accessory
local hat_clone = hat:Clone()
Humanoid:RemoveAccessories() --Comment/Remove this line if you don't want the Player's Avatar Hats to be Removed
Humanoid:AddAccessory(hat_clone) --Finally adds the Hat.
end
end
end)
end
end
end)
Note: You'll need to Edit some lines to make it work, don't Copy and Paste the Code! Instead of that, Study it and try to understand how it works!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Writting an Anwer right now :)