Cloned Parts aren't destroyable?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    To delete iS without making the script wait before making another iS
  2. What is the issue? Include screenshots / videos if possible!
    iS 1 doesent delete when instance:Destroy() is used
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local CAP = require(game.ServerScriptService:FindFirstChild("Clear_ATTACK"))
game.ReplicatedStorage.iceAttack2.OnServerEvent:Connect(function(player, pos)
	local ti = TweenInfo.new(
		0.75, 
		Enum.EasingStyle.Back, 
		Enum.EasingDirection.In, 
		0, 
		true
	)
	local goals = {
		Position = pos + Vector3.new(0, 2.5, 0)
	}
	local num = math.random(5, 10)
	local iceSpike = rs:FindFirstChild("IceSpike")
	local stop = 0
	local table = {}
	while num > -1 do
		local number1 = math.random(10, 20)
		local number2 = math.random(10, 20)
		local number3 = math.random(10, 20)
		local number4 = math.random(1, 10)
		local number5 = math.random(1, 10)
		if number4 > 5 then
			number1 = number1 - (number1 * 2)
		end
		if number5 > 5 then
			number3 = number3 - (number3 * 2)
		end
		local iS = iceSpike:Clone()
		iS.Name = "iS"
		iS.Parent = workspace.Attack_Parts
		iS.Position = Vector3.new(pos.X + number1, pos.Y + number2, pos.Z + number3)            
		iS.CFrame = CFrame.lookAt(iS.Position, pos)
		local tween = ts:Create(iS, ti, goals)
		tween:Play()
		wait(0.1)
		num = num - 1
	end
	print("while loop ended")
	wait(3)
end)

You don’t use Instance:Destroy() anywhere in this code

1 Like

i deleted it becuase it wasnt working, i placed it after num = num- 1

I don’t see the usage of Destroy() anywhere too, but thinking about what you wanna acomplish, you can use spawn(). It creates an function “on the side” and the script continues, meanwhile the function inside spawn still plays until finished

ill search it up and look, thanks for the advice

You could just use game.Debris:AddItem(iS, TimeHere), this prevents any wait()'s from being yielded/waited & would remove the iS variable depending on the time you set it on while the code would still be running

ill look for that too, not sure what that means though

https://developer.roblox.com/en-us/api-reference/class/Debris

(Supposedly that’s what its main cause is)

Yeah, that works too if the only need is for the part is to be destroyed later.

Anyways tho, if he wanna do other kind of stuff like the iS changing color or such, spawn() and coroutine are useful

interesting, ill give solution when it works, its only purpose is to be deleted.

thanks, this service is actually quite usefull, never heard of it though (the script runs fine now)

coroutine > spawn.

Ironically, spawn has a small yield. Go ahead and search this up as I believe there have been topics on why it shouldn’t be used. Just a tip :wink:

1 Like

Alright, I haven’t heard of spawn really but ill find out , thanks