Script to give hats on entry and respawn working only on entry not on respawn?
Asked by
5 years ago Edited 5 years ago
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)
01 | RunService.Stepped:wait() |
03 | local person = game.Workspace:FindFirstChild(player.Name) |
04 | if (person:findFirstChild( "Humanoid" ) ~ = nil and debounce = = true ) then |
06 | local h = Instance.new( "Accessory" ) |
08 | local p = Instance.new( "Part" ) |
11 | p.Position = person:findFirstChild( "Head" ).Position |
14 | p.Size = Vector 3. new( 2 , 1 , 1 ) |
15 | local weld = Instance.new( "Weld" ) |
16 | weld.Name = "AccessoryWeld" |
19 | weld.Part 1 = weld.Parent.Parent.Parent.Head |
23 | game.ReplicatedStorage.ChefHat.Mesh:clone().Parent = p |
24 | h.AttachmentPos = Vector 3. new( 0 , 1 , 0 ) |
25 | p.Mesh.Offset = Vector 3. new( 0 , 0.75 , 0 ) |
28 | print ( "chefs hat given" ) |
end
Players.PlayerAdded:Connect(onPlayerAdded)