Does :GetTouchingParts() work when using tweens?

Hello!

I was just wondering if :GetTouchingParts() worked to detect an object that is mid-tween if that makes sense?

For example, I have a cannon that fires a projectile at a boss, and I’m trying to detect when the hit happens, so I was planning on using :GetTouchingParts() to detect this “touch” without unanchoring the part.

Here’s my script, it appears not to work.

buttonFunction = coroutine.wrap(function(button, proj)
    local core = workspace:WaitForChild('Boss').HumanoidRootPart
    local RS = game:GetService('ReplicatedStorage')
    local tweenService = game:GetService('TweenService')
    local deb = false
    local pressed = false
    local event = RS.Events.Finish
    if pressed == false then
        pressed = not pressed
        button.Parent.Fired.Value = true
        tweenService:Create(button, TweenInfo.new(0.5), {Position = Vector3.new(button.Position.X, button.Position.Y - 0.45, button.Position.Z), Transparency = 0.5}):Play()
        proj.CFrame = CFrame.lookAt(proj.Position, core.Position)
        proj.Anchored = true
        local tween = tweenService:Create(proj, TweenInfo.new(5), {Position = core.Position})
        tween:Play()
        button.Sound:Play()
        repeat print(proj:GetTouchingParts()) wait() until table.find(proj:GetTouchingParts(), core) -- seems to print '{}' infinitely despite there being touching parts.
            if deb == false then
                deb = true
                print('core')
                local part = Instance.new('Part', workspace)
                local health = core.Parent:WaitForChild('Health')
                health.Value = health.Value - 100
                part.Anchored = true
                part.CanCollide = false
                part.Transparency = 1
                part.Position = proj.Attachment.WorldPosition
                local exp = RS.Assets.ParticleEmitter:Clone()
                local val = Instance.new('NumberValue', exp)
                exp.Parent = part
                exp:Emit(1)
                tweenService:Create(val, TweenInfo.new(2), {Value = 100}):Play()
                val:GetPropertyChangedSignal('Value'):Connect(function()
                    exp.Size = NumberSequence.new(val.Value)
                end)
                finish(button.Parent)
        end
    end
end)

TIA for the help!

1 Like

Yeah, it should work. I’m basing that off of the assumption that I was able to set the CFrame of a part and then immediately call GetTouchingParts() to get intersecting parts.

But I always recommend making your own prototype and running some tests.

2 Likes

Thanks for the post, not only because I needed it but I was thinking of doing a robbery system and I needed to give cash everytime the player is inside and stuff, this :GetTouchingParts() must be really useful.

1 Like

Hmmm, it seems not to work when getting the touching parts of the boss or the projectile, just keeps printing {} when there should be a touching part. I’ll add my script to the original post, perhaps there’s something wrong with it.

Have you tried using .Touched event as a better alternative?

1 Like

.Touched doesn’t work when using anchored parts.

Ah, I assumed that the boss was unanchored. In this case, I believe Region3 would be what you are looking for.

1 Like

Oh wait, you meant detect .Touched from the projectile haha, will try that out. Never thought of that, not sure why.

1 Like

I would recommend raycasting (made something similar to fast cast or the perfect melee hit box: raycasting between the last point and the current point). I’m also unsure why your script isn’t working, it looks like it should.

1 Like

Touched event will work as long as one of the intersecting part is unanchored.

1 Like

Actually, I heard somewhere that you can’t use get touching parts on a part that’s noncollide unless you have a touched connection going. That might be the problem, let me do some research really fast.

Edit:
Yup, GetTouchingParts doesn’t work with noncollide parts normally.
Here is the workaround: