Best way to make radiuses?

So basically, I have a Swat AI, which has a rocket launcher, the problem is that the current system is using explosions for radius, which kills the player instantly (which is not what I expected), since the script is big, instead of getting deeper into the code, I have chosen to use a custom radius system, the problem is that my first attempt was using .Touched, which the hitbox ruined everything, since Touched is not very good, the explosion was not able to kill the player if he wasn’t moving. So now I came here to ask some help on creating a way to detect players when they are on a radius. Thanks for reading.

Also, this thread wasn’t useful to me, if you think that I’m doing another duplicated thread because I’m too lazy to search and read articles :stuck_out_tongue: - How do you detect parts around another part with a certain radius?

1 Like

if you are only looking for the players hit, you can try something like this

local players = game:GetService("Players"):GetPlayers()

local pointOfExplosion = Vector3 --the center of the explosion
local radius = 5

local hit = {}
for _, v in pairs(players) do
	local distance = (pointOfExplosion - v:GetPrimaryPartCFrame.p).magnitude

	if distance < radius then
		table.insert(hit, v)
	end
end

(i don’t know if the syntax is right, not in studio)

or you could try using region3 and then doing the loop above but rather than looping through the players, loop through the parts in the region3.

I forgot with a explosion instance, you can also use this

2 Likes

Hello, I just want to say that the script you gave didn’t work to me, and the Explosion Hit neither.

If you want to get parts near your character you have to use DistanceFromCharacter(Vector3) property of a player it returns a number here’s an example.

local Players = game:GetService("Players")

local Rocket = script.Parent
local Radius = 10
local Damage = 50

Rocket.Touched:Connect(function()
	for _,v in next,Players:GetChildren() do
		if (v:DistanceFromCharacter(Rocket.Position) <= Radius) then
			v.Character.Humanoid:TakeDamage(Damage)
		end
	end
	
	Rocket:Destroy()
end)
1 Like

I got a small error in this line

Error: Attempt to call method “GetChildren” (a nil value)

How do I solve this?

Do you have this in your script?

local Players = game:GetService("Players")

Yes I do, 30charsssssssssssssssss

Try using region3 instead of an instance as a hitbox (it’s bad practice)

1 Like

if your looking for damage less proportin to distance.

have a radious hit detector, if hit, then draw a line from hit part to exploding obgect.
compare the distance to the maximum distance and you will get your percentage.

Show me your full code(30 char).

Nevermind! Already fixed, i just wrote :GetPlayers() and later :GetChildren() lol