Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

How to make a script that instantly kill everyone?

Asked by 4 years ago

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

0
hi kingblaze_1000 359 — 4y
0
hi Fr0stPh3onix 79 — 4y
0
hi Optikk 499 — 4y

3 answers

Log in to vote
1
Answered by
iuclds 720 Moderation Voter
4 years ago

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
0
Everyone below me, stop doing stupid stuff. iuclds 720 — 4y
0
Yeh that could work, why didn't I think of that?! lLol kingblaze_1000 359 — 4y
0
Dude, what I did ain't stupid kingblaze_1000 359 — 4y
1
thank you Fr0stPh3onix 79 — 4y
View all comments (3 more)
0
Yes it was. I made something twice as simple. Clearly this guy doesn't know RemoteEvents yet. iuclds 720 — 4y
0
Dude, what you on about kingblaze_1000 359 — 4y
1
You don't need to use remoteevents/functions for a script to kill someone? It ain't an localscript. moo1210 587 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

Log in to vote
-2
Answered by 4 years ago

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)
0
*facepalm maxpax2009 340 — 4y

Answer this question