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

How to make a script that instantly kill everyone?

When a parts parent is the workspace i want it to kill (preferably explode) everyone

I've tried this

if script.Parent.Parent == workspace then
	game:GetChildren("Humanoid").Health = 0
end

it probably looks very wrong but i tried it and i dont have any other solutions

3 comments

0

hi

0

hi

0

hi

3 answers

✓ Accepted answer

Simply getting all players and setting their health to 0

for i,v in pairs(game.Players:GetPlayers()) do 	
	v.Character.Humanoid.Health = 0
end

7 comments

0

Everyone below me, stop doing stupid stuff.

0

Yeh that could work, why didn't I think of that?! lLol

0

Dude, what I did ain't stupid

1

thank you

0

Yes it was. I made something twice as simple. Clearly this guy doesn't know RemoteEvents yet.

0

Dude, what you on about

1

You don't need to use remoteevents/functions for a script to kill someone? It ain't an localscript.

I'm not sure why you'd want a part to kill when it enters the workspace, but it is a little more complicated than that.

First, you need to have an event listener which waits for the part to enter the workspace. You can use ancestrychanged for this:

https://developer.roblox.com/en-us/api-reference/event/Instance/AncestryChanged

Second, :GetChildren() is a function that returns an array of all chidren to the instance it was called on. It cannot scan for specific types, nor does it return anything more than immediate children. As a result, calling :GetChildren() on game returns high level services like the workspace and serverscriptservice.

To amend this issue, you need to find all players first. You can do this easily by doing game.Players:GetChildren(), which returns all of the children to the Players service. This is not enough however, because you need to set all of their character humanoids health to 0. That is when a loop comes in.

To iterate over an array, you can use a for loop like this:

for i,v in pairs (array) do
	--do stuff
end

i will represent the index (or number) in the array, while v is the entry in the array itself.

Using a for loop over all players, you can set v.Character.Humanoid.Health=0.

If you need more help, let me know.

You should find the character of the player and set their health to 0 Also fire a remote event to all clients.

Server script:

if part.Parent == workspace then
	game.ReplicatedStorage.RandomEventName:FireAllClients(0)
end

local script:

game.ReplicatedStorage.RandomEventName.OnClientEvent:Connect(function(newHealth)
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health = newHealth
end)

1 comment

0

*facepalm

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