local victim = script.Victim.Value local owner = script.Owner.Value function…
- User
local victim = script.Victim.Value local owner = script.Owner.Value
function RemoveCollar(VictimHasDied) print("Removing collar") script:WaitForChild("RemoveEvent").Value:FireAllClients()
--ResetAnimation if VictimHasDied then local character = victim.Character local animationScript = character:WaitForChild("Animate") animationScript.idle.Animation1.AnimationId = "rbxassetid://180435571" animationScript.idle.Animation2.Weight.Value = 1 animationScript.jump.JumpAnim.AnimationId = "rbxassetid://125750702" animationScript.fall.FallAnim.AnimationId = "rbxassetid://180436148" animationScript.run.RunAnim.AnimationId = "rbxassetid://180426354" animationScript.walk.WalkAnim.AnimationId = "rbxassetid://180426354" end -- victim.Character.Collar:Destroy() script:Destroy()end
function OnVictimDeath() RemoveCollar(true) end
function OnOwnerDeath() RemoveCollar(false) end
victim.Character.Humanoid.Died:Connect(OnVictimDeath) owner.Character.Humanoid.Died:Connect(OnOwnerDeath)
victim.CharacterRemoving:Connect(OnVictimDeath) owner.CharacterRemoving:Connect(OnOwnerDeath)
line 11: attempt to index nil with 'WaitForChild'
- Assistant
It seems like you're encountering an error on line 11 of your script because
victim.Characteror thescriptitself might not be properly initialized or might not have the expected content at the time the lookup occurs. Here's a slightly modified version of the script with additional safeguards to ensure all necessary objects and properties are correctly available before attempting to manipulate them:local victim = script:FindFirstChild("Victim") and script.Victim.Value local owner = script:FindFirstChild("Owner") and script.Owner.Value if not victim or not owner then warn("Victim or Owner not correctly initialized") return end function RemoveCollar(VictimHasDied) print("Removing collar") local removeEvent = script:FindFirstChild("RemoveEvent") if removeEvent and removeEvent:IsA("RemoteEvent") then removeEvent:FireAllClients() else warn("Missing or incorrect RemoveEvent in script") end -- ResetAnimation if VictimHasDied then local character = victim.Character if character then local animationScript = character:WaitForChild("Animate", 10) if animationScript then animationScript.idle.Animation1.AnimationId = "rbxassetid://180435571" animationScript.idle.Animation2.Weight.Value = 1 animationScript.jump.JumpAnim.AnimationId = "rbxassetid://125750702" animationScript.fall.FallAnim.AnimationId = "rbxassetid://180436148" animationScript.run.RunAnim.AnimationId = "rbxassetid://180426354" animationScript.walk.WalkAnim.AnimationId = "rbxassetid://180426354" else warn("Animate script not found in victim's character") end else warn("Victim's character not found") end end -- if victim.Character and victim.Character:FindFirstChild("Collar") then victim.Character.Collar:Destroy() else warn("No Collar found on the victim's character") end script:Destroy() end function OnVictimDeath() RemoveCollar(true) end function OnOwnerDeath() RemoveCollar(false) end if victim.Character then victim.Character:WaitForChild("Humanoid").Died:Connect(OnVictimDeath) victim.CharacterRemoving:Connect(OnVictimDeath) else warn("Victim's character not found at script initialization") end if owner.Character then owner.Character:WaitForChild("Humanoid").Died:Connect(OnOwnerDeath) owner.CharacterRemoving:Connect(OnOwnerDeath) else warn("Owner's character not found at script initialization") endKey Changes:
- Initialization Checks: Ensure
victimandownerare correctly assigned from the values of corresponding instance names within the script. - Safeguards and Warnings: Additional checks to ensure objects such as
RemoveEvent,character,animationScript, andCollarare valid before trying to access their properties or methods. Appropriate warning messages are added to debug when objects are missing. - Use of
FindFirstChild: To avoid nil references that could lead to errors,FindFirstChildis used with conditional checks and default values for more robust error handling.
This improved script should help prevent runtime errors related to accessing nil object references and provide better diagnostics in the console log for debugging purposes.
- Initialization Checks: Ensure