Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt this kill all the players in the game?

local script:

local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)

if msg:lower():match("killall") then

game:GetService("ReplicatedStorage"):WaitForChild("killall"):FireServer()

end

end)

server script:

local killall = remote:WaitForChild("killall")

local players = game.Workspace:GetChildren()

killall.OnServerEvent:Connect(function()

for i, v in pairs(players) do

if v:FindFirstChild("Humanoid") then

v.Humanoid.Health = 0

print(v.Name)

print(v.Humanoid.Health)

end

end

end)

output: klepolek version 3

0

MR. Pirana

0

baldi

0

but i didnt die, why when the others die(they are npc's with a humanoid inside of them)

1 answer

You used "workspace:GetChildren()" and not "game:GetService("Players"):GetPlayers()". If you do workspace:GetChildren() you'll get stuff such as the Baseplate and models and not the actual players.

Instead, we'll be looping through all of the players, getting the characters, and modifying their health to 0.

local KillAll = game:GetService("ReplicatedStorage").killall

KillAll.OnServerEvent:Connect(function()
	for i,v in pairs(game:GetService("Players"):GetPlayers()) do
		local Character = v.Character
		if Character then
			Character.Humanoid.Health = 0
		end
	end
end)

In the code above we're looping through all of the players. We then make a variable of their character. If their character does exist we change their humanoid's health to 0. If their character does not exist we do not do anything and move on the the next player.

3 comments

0

first the server script cant look into the local players and second off in my code it found the "players" in the workspace and put their humanoid.health to 0, all but mine so from just reading this i can tell it wont work but mine should work

0

... Why would you ask for help, then refuse it? His script does work. and it can look at the local player he just didint put it in as a parameter.

0

Scripts can look into players by using a simple loop. What I'm doing is looping through the table of players, getting their character, and then afterwards changing their humanoid to zero. You're insufferable lmao

This discussion is preserved as it was. New answers, comments, and votes are closed.