Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How should i detect objects inside a part?

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?

3 comments

0

use the parts position, and size. Also the players position to detect if the player is in the part, I hope that helps.

0

Run a loop in the touched event then use the TouchEnded event to stop it.

2 answers

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)

1 comment

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.