Hello! so I have a gui where if a button is clicked, a hat will spawn on the players head. The hat is inside of the player but spawns at 0,0,0 and falls instead of on the players head
this is the script:
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local hats = game.ReplicatedStorage.Hats
script.Parent.MouseButton1Click:Connect(function()
humanoid:AddAccessory(hats.BloxxerCap:Clone())
end)
The issue is probably that player.Character isn’t fully loaded when your script runs. Wrap the humanoid fetch inside the button click like this:
local player = game.Players.LocalPlayer
local hats = game.ReplicatedStorage.Hats
script.Parent.MouseButton1Click:Connect(function()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:AddAccessory(hats.BloxxerCap:Clone())
end
end)
I did try do some more digging while waiting for a response, I forgot to add that I was doing this in a local script and just found out that you cant add accessories to humanoid in a local script so i fixed it by using a remote event. Thanks for replying though!