Check if player is in zone

Localscript inside your tool:

script.Parent.Activated:Connect(function()

local plrs = game.Players:GetChildren()

for i, plr in ipairs(plrs) do
local char = plr.Character
if char then

local distance = (game.Players.LocalPlayer.Character.PrimaryPart.Position - char.PrimaryPart.Position).Magnitude

if distance < 100 --distance in studs then
char.Humanoid.Health.Value -= 10 --damage
RemoteEvent:FireServer(char, 10–damage)
end

end
end

end)

Server side Script:

RemoteEvent.OnServerEvent:Connect(function(plr, char, damage)
char.Humanoid.Health -= damage
end

1 Like

in case your enemies are NPCs place them all into a folder and change game.Players:GetChildren() by your folder:GetChildren()

1 Like

ah this is how it works?
can i make it so i dont have stuff external of tools or characters?

1 Like

just place the remote event inside your tool and the server script too

1 Like

so like just why i need a localscript in the tool?

1 Like

I just noticed you’re not using RenderStepped so just set everything on the localscript into a Script

1 Like

also, when an enemy falls out of the world, the model still remains. how do i delete it after???

1 Like

that way you wont need remotevents

1 Like

…also, when an enemy falls out of the world, the model still remains. how do i delete it after???

2 Likes

if they have humanoids add a :Died() event to destroy the model

1 Like

and that works? i tried it but it didnt realize the died event

1 Like

I don’t understand your post (woekwof)

1 Like

you can use the Touched event and then the TouchEnded event.

Example:

local part = workspace.Part -- insert your part here

part.Touched:Connect(function(touch)
	local Character = touch.Parent
	if Character then
		print("Touching!")
		-- Continue your code here
	end
end)

part.TouchEnded:Connect(function(touch)
	local Character = touch.Parent
	if Character then
		print("Touching Ended!")
		-- Continue your code here
	end
end)

Hope it helps (:

3 Likes

it does actually but im trying to be as performant as possible… im making a new game called “doors and dungeons”

1 Like

You should use Region3 for this as this will check everything inside or :GetPartsInide()

BUT HOW TO damage the enemies if tool is activated?

enemyhumanoid:TakeDamage(10)

enemyhumanoid gotten from the magnitude

There is no debounce here.

i would strongly use magnitude or region3

omg you monitoring my posts??? niceee
however i would also consider using magnitude but idk how to make a ton of entities check if hit at once WITH ONLY USING MAGNITUDE

1 Like

You could use the ZonePlus Module by ForeverHD

Devforum Post:

1 Like