Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to give certain player certain hats when they spawn?

Asked by 5 years ago

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)

0
Writting an Anwer right now :) FullMetalEdward45221 106 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

Ad

Answer this question