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
WHOTEI
(WHOTEI)
August 17, 2023, 6:25am
#23
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
WHOTEI
(WHOTEI)
August 17, 2023, 6:29am
#25
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
WHOTEI
(WHOTEI)
August 17, 2023, 6:30am
#27
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
WHOTEI
(WHOTEI)
August 17, 2023, 6:31am
#29
…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
WHOTEI
(WHOTEI)
August 17, 2023, 6:32am
#31
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
WHOTEI
(WHOTEI)
August 17, 2023, 6:47am
#34
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()
WHOTEI
(WHOTEI)
August 17, 2023, 7:12am
#36
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
WHOTEI
(WHOTEI)
August 17, 2023, 7:34am
#39
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