Why this script doesnt work?

This might be a silly question for many people. However, I am not good at scripting and I am currently learning that! So pls forgive me to ask this silly question

Expected result: Get all the players and kill them one by one

My issue now: I watched a few youtube tutorials to achieve this but they didn’t work. And i tried to code it myself and the players didn’t get killed and there are no errors in the output!

local players = game:GetService("Players")
local player = players:GetPlayers()
task.wait(90)
for _, player in ipairs(player) do
	local hu = player:WaitForChild("Humanoid")
	hu.Health = 0
end

Can someone tell me what’s wrong with this code? (btw my english is bad pls forgive me if there is a lot of grammatical mistakes)

Try this:

local players = game:GetService("Players")
local player = players:GetChildren()
task.wait(90)
for _, player in ipairs(player) do
	local hu = player.Character:WaitForChild("Humanoid")
	hu.Health = 0
end
3 Likes

Is this line intentional? It waits 90 seconds before the killing happens

1 Like

Sorry didn’t test last code.
This one works!

local players = game:GetService("Players")
task.wait(90)
for _, v in ipairs(players:GetChildren()) do
	local hu = v.Character:WaitForChild("Humanoid")
	hu.Health = 0
end
2 Likes

it works thank you so much!

But whats the difference between the script you have sent before and the new one?

The value for the table and singual player were the same, so you were waiting for the humanoid in the player table. And you waited for the humanoid in the player instance and not the character.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.