Clone of a model wont delete

im trying to delete a van model after the tween has finished but its not deleting.

where the problem is:

	tweenTrack2.Completed:Wait()
vanClone:Destroy()
--end)
end)

script:

local event = game.ReplicatedStorage:WaitForChild("SpawnVan")
local killEvent = game.ReplicatedStorage:WaitForChild("killEvent")
local chatService = game:GetService("Chat")
local button = script.Parent


event.OnServerEvent:Connect(function(plr: Player)
	local char = plr.Character
	if char == nil then return end
	--char.Humanoid.WalkSpeed = 0
	--char.Humanoid.JumpHeight = 0
	wait()
	local van = game.ReplicatedStorage:WaitForChild("One Seated Van")
	local vanClone = van:Clone()
	local rigHead = vanClone.Rig:WaitForChild("Head")
	local vcPP = vanClone.PrimaryPart
	local hrp = char.HumanoidRootPart
	local SpawnOFFSET = CFrame.new(-150,1,-5)
	local chainsawSounds = vanClone.chainsawMan["Right Arm"].chainsaw["Pink Shredder Chainsaw"].Handle.sounds
	vanClone.Parent = workspace
	vanClone:PivotTo(char.HumanoidRootPart.CFrame * SpawnOFFSET)
	
	chainsawSounds.chainsawSoundLoop:Play()

	--tween
	local ts = game:GetService("TweenService")
	local tsInfo = TweenInfo.new(
		3,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)

	local tsNewLocation = CFrame.new(150,0,-5)
	local tweenTrack = ts:Create(vanClone.PrimaryPart, tsInfo ,{CFrame = vanClone.PrimaryPart.CFrame * tsNewLocation})
	tweenTrack:Play()
	game.StarterPlayer.StarterCharacterScripts.ragdoll.Enabled = true
	tweenTrack.Completed:Wait()
	
	--chainsawSound

	chainsawSounds.chainsawSound:Play()

	
	--chat
	task.wait(1)
	local sounds = vanClone.Rig.Head.sounds
	chatService:Chat(rigHead, "wagwan bro", Enum.ChatColor.Green)
	wait(.2)
sounds.wagwan:Play()
sounds.wagwan.Ended:Wait()

	wait(.25)
	chatService:Chat(rigHead, "looking like a snack", Enum.ChatColor.Green)
sounds.snacc:Play()
sounds.snacc.Ended:Wait()

wait(.1)
	chatService:Chat(rigHead, "HAHAHAHAHAHA 🤣🤣🤣😭😭", Enum.ChatColor.Green)
	sounds.laugh:Play()
	sounds.laugh.Ended:Wait()
	
	char:PivotTo(vanClone.weldPart.CFrame)
	
	--weld char
	local weld = Instance.new("Weld")
	weld.Name = "characterWeld"
	weld.Parent = vanClone
	weld.Part0 = char["Right Leg"]
	weld.Part1 = vanClone.weldPart
	
	wait(1)
	
	local tsNewLocation2 = CFrame.new(1500,0,-5)
	local tsinfo2 = TweenInfo.new(
		9,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	local tweenTrack2 = ts:Create(vanClone.PrimaryPart, tsinfo2 ,{CFrame = vanClone.PrimaryPart.CFrame * tsNewLocation2})

tweenTrack2:Play()
task.wait(2)


--kill plr + ragdoll
--killEvent:FireClient(plr)

--killEvent.OnServerEvent:Connect(function(plr)

		char.Humanoid.Health = 0
	weld:Destroy()
		
	tweenTrack2.Completed:Wait()
vanClone:Destroy()
--end)
end)
2 Likes

Does every other part of the code work properly till that specific part?

1 Like

yessir! i reviewed everything n tested everything. everything works until up to that second tween.

Add a print right after tweenTrack2.Completed:Wait(), see if you see any log messages

1 Like

i put in this print statement but it doesnt print unfortunately.

	tweenTrack2.Completed:Wait()
	print("tween completed zzzzzzz")
vanClone:Destroy()
--end)
end)

Try placing the Completed:Wait() signal after the Play() method is called and remove the task.wait(2)

1 Like

great suggestion! i did some tinkering w ur suggestion and the problem is is that when my character respawns the script breaks completely, it doesnt delete. not sure if its a bug tbh but i have a vid:

Try killing the character after deleting the van.

1 Like

Add a Humanoid.Died:Connection function and if they reset simply early return and destroy anything that has already been created.

1 Like

@Kilpamations @uisouls

hey guys, tysm 4 ur responses. i got it eventually. yl said something earlier and i tried putting in loops and stuff and got it to work. :slight_smile:

tweenTrack2:Play()
wait(2)

char.Humanoid.Health = 0
	weld:Destroy()
	
	
	if tweenTrack2.Completed:Wait() then
		chainsawSounds.chainsawSoundLoop:Stop()
		vanClone:Destroy()
		
		for i, van in pairs(workspace:GetChildren()) do
			if van:IsA("Model") then
				if van.Name == "One Seated Van" then
					
					for i, sound in pairs(van:GetDescendants()) do
						if sound:IsA("Sound") then
							sound:Destroy()
						end
					end
					
					van:Destroy()
				end
			end
		end
end	
end)