Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using the Touched even when using CFrame to move an object into another?

Asked by 7 years ago

I'm attempting to use the Touched event on a single block that i'm CFraming into what i'm trying to detect. On the Roblox wiki's Touched event page it says that Touched does not fire when the block is CFramed into another. DO you know any workaround? If i use "block.Position = Vct3" the block moves on top of the objects which is undesirable. Same with MoveTo if i put the block in a model.

Images of the Ultimate Goal provided below: Wanted Outcome: http://prntscr.com/etrx9h Unwanted Outcome: http://prntscr.com/etrxg1

Thanks everyone!

Detection_Part.CFrame = CFrame.new(Mouse.Hit.p.x, Mouse.Hit.p.y+(Mouse.Hit.p.y/4), Mouse.Hit.p.z)

--+

Detection_Part.Touched:connect(function(otherPart)

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

GetTouchingParts will do what you're looking for. It returns an array of all CanCollide true parts that are intersecting with the part you called it on, even when CFramed.

Unfortunately it's a method and not an event, so you'd have to stick it in a loop. For example,

while wait(0.5) do
    local parts = script.Parent:GetTouchingParts()

    for i, part in pairs(parts) do
        print(part)
    end
end
0
Excellent, thank you! I'm fine with a loop since it's a temporary operation. I've looked into this method but the biggest problem is that it requires the main block to also be CanCollide. I'll test it out but this may cause problems with players pushing others through the map. Do you have any solution? windows65 2 — 7y
0
Update: I've found a small / dirty workaround. I turn cancollide on, get the parts, and turn it off immediately. I'm still open to better solutions but it works for now. Thank you! windows65 2 — 7y
0
just a note, adding: script.Parent.Touched:Connect(function()end) adds a touchinterest to the part and as a result you can get parts that are not only touching but are also inside your part. mantorok4866 201 — 5y
Ad

Answer this question