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

How should i detect objects inside a part?

Asked by 6 years ago

I was using touched event , but the problem is when the part that is sensible to touch isnt moving, it requires the other parts (characters, etc..) to move and touching. Problem arrises when the part sensible to touch gets created and CFramed in a position that makes the character inside the part... If the character doesnt move, touch event doesnt get triggered. Is there an alternative solution?

0
use the parts position, and size. Also the players position to detect if the player is in the part, I hope that helps. TheGreatSailor 20 — 6y
0
Run a loop in the touched event then use the TouchEnded event to stop it. Lord_CthuIhu 2 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local Parts = {}

script.Parent.Touched:connect(function(Hit)
    local Add = true
    for i,v in pairs(Parts) do
        if v == Hit then
            Add = false
        end
    end
    if Add == true then
        table.insert(Parts, Hit)
    end
    coroutine.resume(coroutine.create(function()
        while wait() do
            for i,v in pairs(Parts) do
                --whatever you want to happen to the part which is defined as v
            end
        end
    end))
end)

script.Parent.TouchEnded:connect(function(Hit)
    for i,v in pairs(Parts) do
        if v == Hit then
            table.remove(Parts,i)
        end
    end
end)
0
so.. I believe this isnt an answer to my question. for that to be activated, it needs a touch event, which isnt triggered in the case of the parts staying still. But thanks Kiriyato 15 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Isn’t there a way besides that messed up geometry scripting?

Answer this question