I'm making a script for an enemy in my game but some weird things are happening pls help
I have a module script in serverscriptservice to handle all the enemies
local EnemyModule = {}
function EnemyModule:FindPlayer(LocalHumanoidRootPart:Part, localhumanoid:Humanoid)
local deb = false
for i, v in workspace:GetChildren() do
if v:IsA("Model") and game.Players:GetPlayerFromCharacter(v) and v:FindFirstChild("HumanoidRootPart") then
local HumanoidRootPart:Part = v:FindFirstChild("HumanoidRootPart")
local magnitude = (LocalHumanoidRootPart.Position - HumanoidRootPart.Position).Magnitude
if magnitude >= 30 then
localhumanoid:MoveTo(HumanoidRootPart.Position)
elseif magnitude >= 1 then
if deb then return end
deb = true
local humanoid = v:FindFirstChild("Humanoid")
humanoid.Health -= 10
end
end
end
deb = false
end
return EnemyModule