Alternative for Touched event?

Hi, so I just noticed that the Touched event isn’t working reliably with my bombs. So, I made a bomb tool that creates an explosion part sphere, and that sphere expands in all directions, then fades out. If players touch that sphere, it’ll kill them. There’s also a freeze bomb that freezes players that collide with the explosion. It creates a block around the player’s character, also anchoring the player’s character as well.

I noticed if somebody throws a damage bomb, and if players collide with it but they’re currently frozen, they won’t take any damage from it.

Any workarounds?? Thanks :slight_smile:

2 Likes

Could you please provide your code so we could help you further?

4 Likes

You could create a Region3 with the explosion and then find parts in the region and damage the player if they are within the region.

2 Likes

Hm, that’s an idea.

Although, it might be imprecise as it’s made with a bounding box, and if I use it for a sphere it could get tricky possibly

Thanks for the reply, I could try messing around with this.

That is the issue, but as the touched event is not working reliably for you, I see this as a viable option, let me know how it works out for you.

1 Like

You could possibly use this, https://developer.roblox.com/en-us/api-reference/function/Player/DistanceFromCharacter

2 Likes

In my experience with using distance from character, you have to get the value every time the humanoid moves so it can get quite hard to deal with debounce wise.

1 Like

Do you think this wouldn’t be that expensive to do though? The only way I see this working is to create Region3’s every time the loop runs to resize the explosion, which is about 30 times.

To my understanding you can expand the region using ExpandToGrid, I do not know if it works the way that you want it to though. Here is where I got this information:

https://developer.roblox.com/en-us/api-reference/datatype/Region3

1 Like

If I’m not mistaken, Region3 is more expensive. You could use DistanceFromCharacter or Magnitude, which you should only have to get once for everyone in the bomb blast radius

1 Like

Artificial explosions typically use raycasts.

4 Likes

Clone the script 2 times so the the touched is more precise? Put the touched event in a render stepped(performance eating probably)? Not sure if both methods work.

Cloning the script would not fix anything, there’s still the possibility that both scripts won’t run or that both scripts will run at the same time (not a good thing!). If this is a costly script, having both scripts run at once would just be a bad idea.

RenderStepped has nothing to do with Touched…? RenderStepped is used in cases of precision (think shooting games), not in the cases of a Touched event. The event would still fire even if the player isn’t touching any of the parts that you want it to touch, and if the resource is costly, it’d just cause more lag to the player.

I don’t believe touched works if both of the colliding parts are anchored

what I’d use is :GetTouchingParts()

local bomb = workspace.Bomb


function getTouchingParts(bomb)
	
	local connection = bomb.Touched:Connect(function() end) -- trick to make :GetTouchingParts() work with cancollide off parts
	local touchingParts = bomb:GetTouchingParts()
	connection:Disconnect()
	
	return touchingParts
	
end

it works with well with spheres and anchored parts, I think it works nicely performance wise too

Personally I’d use GetTouchingParts over Touched in this case because it would be easier to add effects like pulsing damage

source

Region3 Module that works with different shapes including spheres (Alternative)

as for region3s you can use this for support with Balls
Rotated Region 3 Module

5 Likes

Wouldn’t you need to fire a lot of rays in order to catch something?

1 Like

The same applies with a ray cast since your just checking the distance and obstacles. If you don’t want obstacles to block the bomb though, you could just use DistanceFromCharacter. But rays will let you catch the case of their arm or something being in the radius when the measure point isn’t.

Since the bomb size is increasing, you might need to check a few more times if it’s a slow enough speed to matter, but you would need to do that with any method you used unless it’s a connection. However, if it’s going that slow and it’s visible you would be able to see if your character is touching it, so GetTouchingParts would give you more visually accurate results if you fire it enough, though the difference would be small.

2 Likes

Yes you would, but I’m not sure where this question is coming from. Are you concerned about the expense? It’s not expensive or performance hitting at all. You can fire hundreds of rays, provided their lengths are short, every frame.

2 Likes