-
What do you want to achieve?
I want to fix this bug below , as you can see the humanoid health is 0 but the mob is still not dying -
What is the issue?
robloxapp-20240704-1928303.wmv (3.5 MB)
sorry for really bad quality of video but it was the only choice i had
after the tankenemy health is 0 tank enemy doesnt stop walking and doesnt die -
What solutions have you tried so far?
I tried many things but it just made it worse, I also looked at devforum but none of the solution seem to work for me.
local PhysicsService = game:GetService(“PhysicsService”)
local ServerStorage = game:GetService(“ServerStorage”)
local Mob = {}
function Mob.Move(mob, map)
local waypoints = map.waypoints
for waypoint=1, #waypoints:GetChildren() do
local Humanoid = mob:FindFirstChildOfClass("Humanoid",12)
Humanoid:MoveTo(waypoints[waypoint].Position)
Humanoid.MoveToFinished:Wait()
Humanoid:MoveTo(waypoints[waypoint].Position)
Humanoid.MoveToFinished:Wait()
end
ServerStorage.Bindables.DamageBase:Fire(mob.Humanoid.Health/2)
mob:Destroy()
end
function Mob.Spawn(name, quantity, map)
local mobExists = ServerStorage.Mobs:WaitForChild(name)
if mobExists then
for i=1, quantity do
task.wait(0.5)
local newMob = mobExists:Clone()
newMob:PivotTo(map.Part.CFrame)
newMob.Parent = workspace.Mobs
newMob.HumanoidRootPart: SetNetworkOwner (nil)
for i,object in ipairs(newMob:GetDescendants())do
if object:IsA(“BasePart”)then
object.CollisionGroup = “Mob”
end
end
newMob:WaitForChild(“Humanoid”).Died:Connect(function()
newMob.Parent = workspace
wait (3)
newMob:Destroy()
if newMob.Humanoid.Health == 0 then
newMob.Humanoid:ChangeState(Dead)
newMob.Parent = workspace
wait(3)
newMob:Destroy()
end
end)
coroutine.wrap(Mob.Move)(newMob, map)
end
else
warn(“Mob not found:”, name)
end
end
This script is a module script of a Server Script inside of ServerScriptService
local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local Tower = {}
local rs = game:GetService("ReplicatedStorage")
local function NearestTarget(tower,range)
local nearestTarget = nil
for i, target in ipairs (workspace.Mobs:GetChildren())do
local distance = (target.HumanoidRootPart.Position-tower.PrimaryPart.Position).Magnitude
if distance < range then
nearestTarget = target
range = distance
else
return
end
return nearestTarget
end
end
function Tower.Attack(Unit)
local attributs = Unit:GetAttributes()
local target = NearestTarget(Unit,attributs.Range)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health >= 0 then
Unit.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(Unit.PrimaryPart.Position,target:WaitForChild("HumanoidRootPart").Position)
--rs.Events.Animator:FireAllClients(Unit,"Attack") -- has been turned cuz it was causing problems
target.Humanoid:TakeDamage(math.clamp(target.Humanoid.Health,0,attributs.Damage))
task.wait(0.1)
end
wait(0.1)
Tower.Attack(Unit)
return target
end
function Tower.Spawn(player,name,cframe)
local TowerExists = rs.OwnedTowers:FindFirstChild(name)
if TowerExists then
local newTower = TowerExists:Clone()
local humanRootPart = newTower.HumanoidRootPart or newTower.PrimaryPart
humanRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
newTower.HumanoidRootPart: SetNetworkOwner(nil)
local bodygyro = Instance.new("BodyGyro")
bodygyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
bodygyro.D = 0
bodygyro.CFrame = newTower.HumanoidRootPart.CFrame
bodygyro.Parent = newTower.HumanoidRootPart
for i,object in ipairs(newTower:GetDescendants())do
if object:IsA("Part")then
object.CollisionGroup = "Tower"
end
end
coroutine.wrap(Tower.Attack)(newTower)
else warn("Requested Tower not found: ".. Tower.Name)
end
end
rs.Events.SpawnTower.OnServerEvent:Connect(Tower.Spawn)
return Tower
***This script is a module script of a Server Script inside of ServerScriptService***
idk how to explain this any more further please help.