Hi all! So, for my game, I've wanted to create a Hat Giver according to if they have a gamepass or not! But, with this summons a new problem; too many hats! I would like to know how to remove hats upon entering a game, and if they player is a boy, give them a specific hair, and if the player is a girl if them a specific hair!
I've yet to attempt a code for this, because I wouldn't even know where to begin, so anything is help! Thank you guys!
Server Script
local Market = game:GetService("MarketplaceService") game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) -- Checks if Player has Gamepass (Change 0 to the Gamepass ID) if Market:UserOwnsGamePassAsync(Player.UserId, 0) then wait(0.1) -- Removes Previous Hair for i, v in pairs(Character:GetChildren()) do if v:IsA("Accoutrement") then v:Destroy() end end -- Creates a New Accessory local newaccessory = Instance.new("Accessory") newaccessory.Name = "NewHair" local handle = Instance.new("Part") handle.Name = "Handle" handle.CanCollide = false handle.Anchored = false handle.Size = Vector3.new(1, 1, 1) handle.Parent = newaccessory local weld = Instance.new("Weld") weld.Parent = handle weld.Part0 = handle weld.Part1 = Character:WaitForChild("Head") local mesh = Instance.new("SpecialMesh") mesh.Scale = Vector3.new(1, 1, 1) mesh.Parent = handle -- Checks Gender based on if the player owns an asset -- Change the id of the below (mesh / texture / cframe offset] for the new hair if Market:PlayerOwnsAsset(Player, 63690008) then -- Default Boy Hair mesh.MeshId = "http://www.roblox.com/asset/?id=0" mesh.TextureId = "http://www.roblox.com/asset/?id=0" weld.C0 = CFrame.new(0, 0, 0) elseif Market:PlayerOwnsAsset(Player, 451220849) then -- Default Girl Hair mesh.MeshId = "http://www.roblox.com/asset/?id=0" mesh.TextureId = "http://www.roblox.com/asset/?id=0" weld.C0 = CFrame.new(0, 0, 0) end end end) end)
Explanations of the functions are written in the script
The player.CharacterAdded Event is used to get the player's Character when they join the game
There is no property to determine gender, but players are also unable to remove the default hairs from their inventory, the one's given when they join roblox based on their gender choice
Retrieving a player's gender is not possible in Roblox because it's illegal to give out personal information like that.
As for removing hats upon entering the game, you can use the following code :
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) wait() -- giving a bit of time for the hats to load for i,v in pairs(character:GetChildren()) do if v:IsA("Accoutrement") then v:Destroy() end end end) end)
Hope this helps!