Can't destroy model or add it to debris service

So I’m creating effect using model which moves with vector force, but I can’t destroy model after effect, so here is my script, it starts after remote event fired from server to client(it’s local script), it’s located in started players scripts and model of ben is located in ReplicatedStorage , it looks like vector force works, but I can’t destroy the model, prints works too and it says that parent of model is nil
All you need:

		print("Ben")  -- line 34
                local projectile = objectToAttack:Clone()
		Debris:AddItem(projectile, 0.5)
		objectToAttack.Parent = workspace
		for i,v in pairs(objectToAttack:GetDescendants()) do
			if v:IsA("BasePart") then
				--v.Anchored = true
				--v.CanCollide = false
			end
		end
		objectToAttack:MoveTo(target.Head.Position + Vector3.new(0,2,0))
		local distanceToMob = (target.HumanoidRootPart.Position - tower.HumanoidRootPart.Position).Magnitude
		--local projectileTween = TweenService:Create(projectile.HumanoidRootPart, TweenInfo.new(0.5), {Position = target.HumanoidRootPart.Position})
		print(projectile.HumanoidRootPart.Position) -- line 47
		--projectileTween:Play()
		--local vectorForce = Instance.new("AlignPosition")
		local vectorForce = Instance.new("VectorForce")
		local Attachment0 = Instance.new("Attachment")
		local Attachment1 = Instance.new("Attachment")
		Attachment0.Parent = projectile.HumanoidRootPart
		Attachment1.Parent = projectile.HumanoidRootPart
		Attachment0.CFrame = target.Head.CFrame * CFrame.new(0,5,0)
		Attachment1.CFrame = target.Head.CFrame
		vectorForce.Attachment0 = Attachment0
		vectorForce.Attachment1 = Attachment1
		--vectorForce.MaxForce = distanceToMob
		vectorForce.Force = target.Head.Position
		vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		--vectorForce.Magnitude = distanceToMob
		--vectorForce
		--vectorForce.MaxForce = 100000
		vectorForce.Parent = projectile.HumanoidRootPart
		vectorForce.ApplyAtCenterOfMass = true
		vectorForce.Enabled = true
		--vectorForce.Force = Attachment1.Position 
		vectorForce.Visible = true
		--vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		--lineForce.
		Debris:AddItem(projectile, 0.5)
		print(projectile.Parent) -- line 73
		print(projectile.HumanoidRootPart.Position) -- line 74
		--projectileTween.Completed:Wait()
		print(projectile.HumanoidRootPart.Position) -- line 76 
		print("Moved") -- line 77
		task.wait(0.5)
		print(projectile.Parent) -- line 79
		projectile:Destroy() -- line 80

image

2 Likes

I’m not sure about why, but what if you put a function that fires when the projectile.Parent is changed?
It might give you a reference to when the change is actually occuring.
Is the model still in the workspace? If so can you select it to see what it’s parent is?

1 Like

It only prints once when I put it into workspace by using script, I mean that model is still in workspace, it’s parented to workspace

1 Like

I’ve got no clue, but how about this?
Is it possible that you’ve got 2 scripts running, or that there are 2 versions of the model and one is getting destroyed by the other script so it’s not being recognized by this one.
Try play testing and pause during the time the projectile is moving to see if there are 2 copies of it.

2 Likes

Oh, yep, I found the problem, so I just parented instead of clone the og model, sorry for this😅
Like you see in line 37 I parent original object to workspace instead of it’s clone, so yep, thanks for help😅

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.