Quick question about TweenService

I’ve recently coded this and I wanted to know if my Tween stops playing when my Projectile part gets destroyed or I have to manually stop it.

local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")
local Debris = game:GetService("Debris")
 
function Shoot(Character, Origin, Direction)
    local Projectile = Instance.new("Part")
    Projectile.Name = "Projectile"
    Projectile.Size = Vector3.new(0.5, 0.5, 0.05)
    Projectile.Transparency = 1
    Projectile.CanCollide = false
    Projectile.Parent = Workspace
    Projectile.CFrame = CFrame.new(Origin, Direction)
    
    local Line = Instance.new("LineHandleAdornment")
    Line.Adornee = Projectile
    Line.Color3 = Color3.fromRGB(255, 235, 140)
    Line.Thickness = 2
    Line.SizeRelativeOffset = Vector3.new(0, 0, 0)
    Line.Length = 0
    Line.CFrame = CFrame.new()
    Line.Parent = Projectile
    
    local Mover = Instance.new("BodyVelocity")
    Mover.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    Mover.Velocity = Projectile.CFrame.LookVector * 250
    Mover.Parent = Projectile
    
    Projectile.CFrame = Projectile.CFrame * CFrame.Angles(math.rad(180), 0, 0)
    
    local DropForce = 1
    local YForce = (Workspace.Gravity * Projectile:GetMass() * DropForce)
    
    local Drop = Instance.new("BodyForce")
    Drop.Force = Vector3.new(0, -YForce, 0)
    Drop.Parent = Projectile
    
    local Tween = TweenService:Create(Line, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false, 0), {Length = 25})
    Tween:Play()
    
    Projectile.Touched:Connect(function(Hit)
        local CharacterTouched = Hit.Parent
        if CharacterTouched then
            local Humanoid = CharacterTouched:FindFirstChildWhichIsA("Humanoid")
            if Humanoid then
                if Character then
                    if CharacterTouched == Character then
                        
                    else
                        print("Hit player " .. CharacterTouched.Name)
                        Projectile:Destroy()
                    end
                else
                    print("Hit player " .. CharacterTouched.Name)
                    Projectile:Destroy()
                end
            end
        end
    end)
    
    Debris:AddItem(Projectile, 5)
end
2 Likes

Hmm, I don’t know. But, I do know how you can find that out yourself. Change how fast the projectile moves, make it really slow, then open up the explorer, and mess with the projectile. Run any tests you need, then just tweak the speed back to normal after you have your results.

1 Like

Would it be good to have a loop printing the current state of my Tween variable?

Yeah, that’ll help. The entire point of the print statement is too debug code. Give it a try.

1 Like

I generally suggest against loops but for testing they are great. Presumably destroying the projectile will also destroy any still running tweens.

1 Like

I’ll mark it as the solution but I’m still going to test the print thing later.

1 Like