-
I’m trying to force the server to kill any object that has a humanoid health value below 0 because for some reason the humanoid:takedamage function is causing the health to go into the negatives and won’t fire the is.dead function but I’m not getting any errors.
-
The issue is stated as the above, the humanoid health will go passed 0 into the negatives and doesn’t seem to be firing the is.dead function, so I’m trying to find work arounds, here’s a screenshot of what’s happening. What’s interesting is that the humanoid will eventually reach 0 after a few seconds or so.
-
I’ve tried calling for all humanoids and their health value but for some reason it only works on players and not non player models with humanoids, I’ve tried forcing them to delete any non player humanoid models when their humanoid health goes to 0 but that still hasn’t worked, perhaps I’m coding it incorrectly?
All I’m trying to do is force the humanoid of every humanoid to reach instantly go to zero if the humanoid reaches below 0 for any interval.
-- HumanoidHealthFixer Script
-- Get the Players service
local Players = game:GetService("Players") and ("Models")
-- Function to fix humanoid health
local function fixHumanoidHealth(humanoid)
if humanoid.Health < 0 then
humanoid.Health = 0
end
end
-- Connect to the PlayerAdded event
Players.PlayerAdded:Connect(function(player)
-- Connect to the CharacterAdded event
player.CharacterAdded:Connect(function(character)
-- Check if the character has a Humanoid
if character:FindFirstChild("Humanoid") then
-- Fix the humanoid health
fixHumanoidHealth(character.Humanoid)
end
end)
end)
-- Iterate through all existing players
for _, player in Players:GetPlayers() do
-- Check if the player has a character
if player.Character then
-- Check if the character has a Humanoid
if player.Character:FindFirstChild("Humanoid") then
-- Fix the humanoid health
fixHumanoidHealth(player.Character.Humanoid)
end
end
end
-- Iterate through all models in the workspace
for _, model in game.Workspace:GetDescendants() do
-- Check if the model has a Humanoid
if model:FindFirstChild("Humanoid") then
-- Fix the humanoid health
fixHumanoidHealth(model.Humanoid)
end
end
Not exactly sure what I’m doing wrong here?