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

How to position player hats?

Asked by 6 years ago
Edited 6 years ago
game.Players.PlayerAdded:connect(function(player)
    player.CanLoadCharacterAppearance = false
    local characterArmour = script["Grim Reaper"]
    if characterArmour then
        player.CharacterAdded:connect(function(character)
            if character then
                for _, v in pairs(characterArmour:GetChildren()) do
                    if v.Name == "Handle" then
                        local handle = v:Clone()
                        local accessory = Instance.new("Accessory", character)
                        handle.Parent = accessory
                        handle.FormFactor = "Custom"
                        handle.Size = Vector3.new(2, 1, 1)
                        accessory.AttachmentPos = Vector3.new(0, 0.5, 0)
                        handle.Anchored = false
                    end
                end
            end
        end)
    end
end)

I'm trying to get a part to be attached to the players head, like a hat. The only problem I have is when I change the handle to something else, it changes how it's placed on the character. How can I make it so it always put the handle on the players head as if it were a normal hat?

EDIT Images

1 answer

Log in to vote
1
Answered by
Wiscript 622 Moderation Voter
6 years ago

Instead of over-complicating things, you should instead use InsertService.

This will take the accessory straight from the catalog and right into the player. The script would look a little bit like this.

game.Players.PlayerAdded:connect(function(p)
    repeat wait() until p.Character -- (WAITING FOR CHARACTER)
    local hatId = 28276664 -- Change to whatever you want it to be
    local insertService = game:GetService("InsertService") -- Getting insertService
    insertService:LoadAsset(hatId):GetChildren()[1].Parent = p.Character -- Loading it  into the character
end)

The script above works because it's getting the accessory and placing it straight into the character. The accessory already comes with all the positioning, so all you really need to do is that.


If you want to insert multiple hats at the same time, you can do so like this

local hats = {11748356,1235488,124730194} -- Accessories IDS go in here
game.Players.PlayerAdded:connect(function(p)
    repeat wait() until p.Character -- (WAITING FOR CHARACTER)
    local insertService = game:GetService("InsertService") -- Getting insertService
    for i,v in pairs(hats) do
        insertService:LoadAsset(v):GetChildren()[1].Parent = p.Character -- Loading in the hats
    end
end)

For a custom hat, you would need the hat to be somewhere in the game, and cloning it right into the player

game.Players.PlayerAdded:connect(function(p)
    repeat wait() until p.Character -- (WAITING FOR CHARACTER)
    script:WaitForChild("ClockworksShadesYellow"):Clone().Parent = p.Character -- Cloning hat into the player
end)

The hat as you can see is already inside the script, so we're just cloning it.

And it all works, perfectly PLAYER WITH THE CUSTOM HAT

0
I mean, it kinda works, but I'm using custom hats, and when I load them in, they dont position correctly NinjoOnline 1146 — 6y
0
I'll edit my question, I have positioned the hats to a player head on a model. I clone the hat and the head into the player. How can I get the hat to be cloned to the same position as the 'fake' head? You can see the hat spawns above the players head. I know I could adjust the attachmentpos, but its different for each hat. I just want every hat to spawn on the same position for every player NinjoOnline 1146 — 6y
Ad

Answer this question