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

How can i find all of the players humanoids at once to run a script on them?

So Yeah i am making a script for my own game cause i am the admin and i made my own gui and it has a kill all feature and it uses a remote i have in game Here is the script ive made local A_1 = game:GetService("Workspace").NAME.Humanoid local A_2 = 10000 local A_3 = "melee" local Event = game:GetService("ReplicatedStorage").dmg Event:FireServer(A_1, A_2, A_3)

I was wondering if i can select all rather than typing each ones name and then running the remote

1 comment

0

Send a message to the server and then have the server fire it back to all clients to kill themselves

2 answers

--ur script
    
        local A_1 = game:GetService(“Workspace”).NAME.Humanoid  
        local A_2 = 10000  
        local A_3 = “melee”  
        local Event = game:GetService(“ReplicatedStorage”).dmg  
        Event:FireServer(A_1, A_2, A_3)
    
    
        --local script
        for i, v in pairs(game.Workspace:GetDescendants() do
        if v:IsA("Humanoid") then
        local humanoid = v
        game.ReplicatedStorage:WaitForChild("dmgEvent"):FireServer(v, A_2)
        end
        end
        
        --server script
        game.ReplicatedStorage:WaitForChild("dmgEvent").OnServerEvent:Connect(function(player, v, A_2)
        v:TakeDamage(A_2)
        end)

this will locate every single humanoid in the game and kill them off, and i have in mind that u can use :TakeDamage but im not sure, otherwise u can just do v.Health = v.Health - A_2

ur idea of putting every player name in the script would just break since that player may not be in the server

1 comment

0

do please accept this answer if u choose to use it

Hello Zayadoo! The previous response WONT WORK! It violates filtering enabled. Instead, we can use a for loop to create a table of the humanoid instances and kill them all. All done on the server! Lets get started:

SETUP

  1. Create a local script under the button to kill all players
    • Name the script "Detector"
  2. Create a remote event in ReplicatedStorage
    • Name it "KillAll"
  3. Create a script in server script service
    • Name it "Kill Receiver"

Scripting

Detector local script:

killEV = game:GetService("ReplicatedStorage"):WaitForChild("KillAll")
 
script.Parent.MouseButton1Click:Connect(function()
    killEV:FireServer()
end)

Receiver Server Script:

killEV = game:GetService("ReplicatedStorage"):WaitForChild("KillAll")
 
killEV.OnServerEvent:Connect(function(_)
    local humanoids = {}
    for _,v in pairs(game.Players:GetChildren()) do
	    if v.Character then
		    table.insert(humanoids, workspace:FindFirstChild(v.Name).Humanoid)
		end
	end
	for _,v in pairs(humanoids) do
		v.Health = 0
	end
end)

Script Context

In the local script, we detect when the button is pressed and then fire an event based on that. We then recieve that in the server. From there, we use a for loop to get all of the current players humanoids and then use another loop to set all of the humanoids healths' to 0, thus killing them. With any questions/comments/concerns, please feel free to comment or reply to my post. ~mc3334

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