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
task.wait(5)
sound:Play()
lighting.Brightness = 3
lighting.Ambient = Color3.new(255,0,0)
lighting.FogColor = Color3.new(255,0,0)
for i = 1,100 do
lighting.FogEnd -= 1000
lighting.ExposureCompensation += 0.1
task.wait(0.01)
end
sound2:Play()
task.wait(7)
lighting.FogEnd = 0
lighting.Ambient = Color3.new(0,0,0)
lighting.TimeOfDay = "00:00:00"
sound3:Play()
for i2 = 1,200 do
humanoid.MaxHealth -= 100
task.wait(0.05)
end
lighting.FogEnd = 100000000000000000000
lighting.ExposureCompensation = 0
lighting.TimeOfDay = "14:00:00"
end
end
while true do
task.wait(0.05)
DESTRUCTION()
end
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!
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
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.
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.