Tween service isn't working correctly

Hello everyone! This is my first time posting, so the post might be a bit confusing!

So here, I have a module script, that I use for a simple ground break type of effect, and it works perfectly fine, until it doesn’t…What I want, is to pop the created parts up(since the ground is broken you know…), and then wait some time, before popping it back to the initial position…and the pop up tween works fine, but the other one, the one where the parts have to pop back to the initial position doesn’t…I would love to know why…it doesn’t even print(‘Played’).

local module = {}
local ts = game:GetService('TweenService')

function module.groundBreakVFX(hrp, circleSize, requiredParts, requiredAngleAdd)
	local rayParams = RaycastParams.new()
	rayParams.FilterDescendantsInstances = {workspace.DebrisFolder}
	rayParams.FilterType = Enum.RaycastFilterType.Exclude

	local angle = 0

	for i = 1, requiredParts do
		local size = math.random(2, 3)
		local part = Instance.new('Part')
		part.Anchored = true
		part.CanCollide = false
		part.Size = Vector3.new(1, 1, 1)
		part.CFrame = hrp.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(angle), 0) * CFrame.new(circleSize, 5, 0)
		game.Debris:AddItem(part, 5)

		local RayCast = workspace:Raycast(part.CFrame.p, part.CFrame.UpVector * -100, rayParams)

		if RayCast then
			part.Position = RayCast.Position + Vector3.new(0, -5, 0)
			part.Size = Vector3.new(size, size, size)
			part.Material = RayCast.Instance.Material
			part.Color = RayCast.Instance.Color
			part.Orientation = Vector3.new(math.random(-180, 180), math.random(-180, 180), math.random(-180, 180))
			part.Parent = workspace.DebrisFolder

			local Tween = ts:Create(part, TweenInfo.new(0.25, Enum.EasingStyle.Bounce, Enum.EasingDirection.InOut), {Position = part.Position + Vector3.new(0, 5, 0)}):Play()

		else
			part:Destroy()
		end
		angle += requiredAngleAdd
	end
	
	task.wait(2)
	print("Played")
	for _, part in workspace.DebrisFolder:GetChildren() do
		print("Tweening part down")
		local tween2 = ts:Create(part, TweenInfo.new(0.25, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Position = part.Position + Vector3.new(0, -5, 0)})
		tween2:Play()
	end
end

return module
2 Likes

Hmm, strange. Where does the script gets before it stops?
i mean what is it’s breaking point where it stops executing lines

At the “task.wait(2)” line…because if I print something just before that line, it prints it out

If you reduce the wait time to a lower number, does the rest of the script play as expected?

No…that is what is weird…but if I completly remove it, it works…but the thing is, that the player doesn’t get to see the rocks with that, because they go down really quickly…

try to use the debris service after changing the part parent into the DebrisFolder folder

or add it after tween2 gets completed

Hello! Tried it in another game, it works! I don’t know why it sometimes work and sometimes it doesn’t, even though the application was the same…hmm

1 Like

maybe there is another script deleting them , can you check if there is any script can delete them ?