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

Is There Any Other Touch Method Instead of TouchInsterest Or :GetTouchingParts?

I cant use any oth those cause touch interest dont always get the person if the block is anchored and cancollide = false and cant use :gettouchingpartsa cause i want the part to becancollide = false

3 comments

0

.Touched

0

It's probably overkill, but you could also make a Region3 slightly larger than the part (as long as it's axis-aligned), and use GetPartsInRegion3 to find the parts touching it. There are much better ways, depending on your specific situation.

0

can u show me cause last time i used region3 i could not get it right and it was glitchy

1 answer

You could listen for the Touch and TouchEnded events, adding each part added to a weak-keyed dictionary (so that it won't keep Destroyed parts in memory), like so:

local part = script.Parent
local parts = setmetatable({}, {__mode="k"})
part.Touched:Connect(function(p)
	parts[p] = true
end)
part.TouchEnded:Connect(function(p)
	parts[p] = nil
end)

I sometimes find that TouchEnded won't fire properly, which means you should improve the script to automatically remove a part from parts if it moves some distance away.

4 comments

0

it worked but when ever i shoot the kamehameha it starts lagging... I know its touch interest. know any fix?

1

Use table.remove, making a key nil does not remove it from the table.

1

you can't use table.remove for a key inside a dictionary. This is correct.

0

I don't get why you used a metatable, and overall this method seems extremely pointless to me in most situations.

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