Okay so i have a script that removes all hats from entering and respawning characters, i tried to add this to it and couldnt. so instead i have 2 seperate scripts, this one adds a chef hat to all players. For whatever reason i get this in the output
"Something unexpectedly tried to set the parent of Accessory to NULL while trying to set the parent of Accessory. Current parent is DemonsEmperor."
The script ends up running, working, and even prints at the end. BUT, when i reset to test out if it re-runs, it wont. So either it crashes during the first run or ive messed up and its only on player entered.
Help please, this is my script!
local Players = game:GetService("Players") local RunService = game:GetService("RunService") debounce = true
function onPlayerAdded(player)
RunService.Stepped:wait()
wait(2)
local person = game.Workspace:FindFirstChild(player.Name)
if (person:findFirstChild("Humanoid") ~= nil and debounce == true) then
debounce = false
local h = Instance.new("Accessory")
h.Parent = person
local p = Instance.new("Part")
h.Name = "ChefHat"
p.Parent = h
p.Position = person:findFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(2, 1, 1)
local weld = Instance.new("Weld")
weld.Name = "AccessoryWeld"
weld.Parent = p
weld.Part0 = p
weld.Part1 = weld.Parent.Parent.Parent.Head
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
game.ReplicatedStorage.ChefHat.Mesh:clone().Parent = p
h.AttachmentPos = Vector3.new(0, 1, 0)
p.Mesh.Offset = Vector3.new(0, 0.75, 0)
wait(0.5)
debounce = true
print("chefs hat given")
end
end Players.PlayerAdded:Connect(onPlayerAdded)

2 comments
im new to scripting helpers so idk why it looks like this format, but it seems readable
but the scripts inside the 2 ~ 's