Help me debug my global script that doesn't take away player's max health

Hello everyone, here’s my problem with my script I tried to write.

local sound = script["zombie evil laugh"]
local sound2 = script["Start Charge"]
local sound3 = script["nightmares jumpscare fnaf"]
local lighting = game:GetService("Lighting")
local isActive = false
local player = game:GetService("Players")
local humanoid = player.Parent:FindFirstChild("Humanoid")

local function DESTRUCTION(kill)
	if not isActive then
		isActive = true
		lighting.Brightness = 3
		lighting.Ambient =,0,0)
		lighting.FogColor =,0,0)
		for i = 1,100 do
			lighting.FogEnd -= 1000
			lighting.ExposureCompensation += 0.1
		lighting.FogEnd = 0
		lighting.Ambient =,0,0)
		lighting.TimeOfDay = "00:00:00"
		for i2 = 1,200 do
			humanoid.MaxHealth -= 100
		lighting.FogEnd = 100000000000000000000
		lighting.ExposureCompensation = 0
		lighting.TimeOfDay = "14:00:00"

while true do

For context, I’m trying to create a global script in the workspace that after a set period of time, the script will kill a player without using any parts, just a script. However, the script bugs at line 29, which doesn’t kill the player as desired. I know what the problem is being caused and it has to do with

local player = game:GetService("Players")
local humanoid = player.Parent:FindFirstChild("Humanoid")

. However, I can’t figure out how to rewrite or debug the issue with them and even writing local humanoid = kill.Parent:FindFirstChild("Humanoid") inside the function is futile. Could someone please help me debug the script, so it can kill players after reaching for i = 1,200? Thanks!

1 Like

You are using MaxHealth instead of Health because MaxHealth is the max number of hp a humanoid can have while Health is what changes when humanoids take damage
And I would suggest doing

humanoid.Health = 0

so that any player that is over 100 health dies no matter what

1 Like

Tried it, didn’t work. As I’ve said, the underlying problem has to do with these 2 lines.

local player = game:GetService("Players")
local humanoid = player.Parent:FindFirstChild("Humanoid")

humanoid.MaxHealth/Health = 0 wouldn’t change it.

You are getting the parent of the players service instead of the parent of the actual players inside of the service.

Are you getting errors when you run this? I would assume your humanoid variable is nil because you are actually searching the Game for a Humanoid which doesn’t seem likely. Maybe you can describe a bit more exactly what you are trying to do. Like do you want it every so often to grab a random player and kill them or is it a very specific player…etc…?

The script is global. I am trying to make it so that after a certain period of time, the script kills all players regardless if they have godmode or not.

For context, when the fog turns completely red and the sky becomes midnight, the players are supposed to be instantly killed.

Oh I see what’s wrong and I didn’t see that part oops

For the humanoid variable it is calling for the parent for the Players service which doesn’t work

By global I assume that’s a server script so you would have to go through the list of Players

for _, plr in pairs(game.Players:GetPlayers()) do
	plr.Character.Humanoid.Health = 0

Where should I put it at to make it work? The script is in workspace. If it works, tell me where I am supposed to put it at.

Try Replacing This:

local player = game:GetService("Players")
local humanoid = player.Parent:FindFirstChild("Humanoid")

With This:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Inside of the destruction function, and whenever you want to kill all the players. Alternatively, you could make another function and call the function whenever you want to kill all the players inside of the destruction function.

Tried it, but no errors popped up and I wasn’t being instantly killed.