#Help With Enemy Script

1 messages · Page 1 of 1 (latest)

spiral sand
#

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
gritty garnet
#

What are the weird things happening?

spiral sand
#

well for some reason i think the enemy is doing damage to me within 30 studs instead of 1

gritty garnet
#

Isn’t it because you put magnitude >= 30?

#

Nvm

#

Oh it’s because you put magnitude >= 1 instead of <= 1

spiral sand
#

O ok thx ima try that