Hello, I created this code but the accessory appears on the floor of the basepale (workspace) someone could help me put the hat on the player’s head, please
Script (startercharacterscript)
local player = game.Players.LocalPlayer
Repeat wait() until player:WaitForChild(“Character”):WaitForChild(“HumanoidRootPart”)
local hat = player.Character:WaitForChild(“TopHatE”)
The accessory appears on the floor, and I need to fix it.
Don’t know if it helps, but I achieve it with the following:
local skull = ServerStorage.Pickups.Disease -- The accessory in ServerStorage
function linkSkull(character)
local humanoid = character:WaitForChild("Humanoid")
-- Create the Accessory.
local disease = Instance.new("Accessory")
disease.Name = "Disease"
local handle = skull:Clone()
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1, 1)
handle.Parent = disease
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0, 2, 0)
faceFrontAttachment.Parent = handle
-- Attach the Accessory to the humanoid.
humanoid:AddAccessory(disease)
end
I am not saying it is the right way to go about it, as I use a custom mesh and not something from the catalog
local hat = game.ServerStorage.Helmet
local part = script.Parent
function giver (character)
local humanoid = character:WaitForChild("Humanoid")
local Accessory = Instance.new("Accessory")
Accessory.Name = "AccesoryHat"
local handle = hat:Clone()
handle.Name = "Handle"
handle.Size = Vector3.new(1,1,1)
handle.Parent = Accessory
local hatAttachment = Instance.new("Attachment")
hatAttachment.Name = "hatAttachment"
hatAttachment.Position = Vector3.new(0,2,0)
hatAttachment.Parent = handle
humanoid:AddAccessory(Accessory)
end
script.Parent.Touched:Connect(function()
giver()
end)
Put the hat in a folder called “Hats” in ServerStorage.
Place this script inside a part named the same as the hat.
Script
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
Hats = ServerStorage:WaitForChild("Hats")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit.Parent:FindFirstChild(script.Parent.Name) then
Hats[script.Parent.Name]:Clone().Parent = hit.Parent
end
end
end)