Pet will not destroy! (3rd and hopefully final attempt)

Hey there,

for awhile now I have tried multiple to destroy the pets in my simulator game when a player resets, I have talked to people on the forum two, times about this and still I have not figured out a solution, so I am going to try again.

Every time someone resets, their pet should destroy through this script which is inside the pet

local TweenService = game:GetService("TweenService")
local Object = script.Parent
local NAME = Object.NameValue
wait(3)
if NAME.Value ~= nil then
	local character = NAME.Value
	script.Parent.Head.AlignOrientation.Attachment1 = character:WaitForChild("Head").NeckRigAttachment
else
	Object:Destroy()
end
while true do
	wait()
	local character = NAME.Value
	print(character.Humanoid.Health)
	if character.Humanoid.Health >= 0 then
		local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
	 	
		local tween = TweenService:Create(Object.Head, tweenInfo, {CFrame = character.Head.NeckRigAttachment.CFrame:ToWorldSpace(character.Head.CFrame * CFrame.new(2, 1, 1))} )
	 
		tween:Play()
	else
		Object:Destroy()
	end	
end

From what I see, it isn’t catching when the player gets reset, so it isn’t destroying, but I am out of ideas…

This issue becomes even stranger when this doesn’t work from my rebirth script…

for i, pet in pairs(game.Workspace.Pets:GetChildren()) do
	if pet.NameValue.Value == player.Name then
		print("Destroy PET!!!")
		pet:Destroy()
	end
end

this is what the pet looks like when it is connected to the character

I am hoping to FINNALY figure this out, does anyone see a potential problem or issue???

This might be the issue. You should use > instead of >=, since the player can be dead if their health is at 0

You could also use Humanoid | Roblox Creator Documentation, to know when the humanoid died, instead of using a loop

5 Likes

Ok, I tried using it, and thanks it worked for the resetting, but I have one more thing to ask, I thought that loading characters is the same as resetting, but then I remembered that it actually kills the player when you reset. I am using :LoadCharacter for a lot of my scripted resetting, so the character isn’t actually dying, so is there a way to catch when the character gets loaded??

Yeah, you can use Player | Roblox Creator Documentation
You can read the documentation for more information

2 Likes

Duh! Why didn’t I think of that. My brain sometimes… Thanks for the help!

1 Like