Hi there! I am having a problem with my pet not destroying when I reset my character, and it doesn’t make sense…
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
if NAME.Value ~= nil then
if character:FindFirstChild("Head") 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
else
Object:Destroy()
end
end
In the while loop I have two spots where if the character is destroyed it will destroy itself, the second just for extra precaution. Could someone tell me what I am missing? It just won’t destroy when the character dies.