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

Kill all script not killing everyone/killing people too many times?

This is a regular script thats disabled and gets enabled by another script thats also not a local script. I want it to just kill everyone on the server ONCE, but for some reason it either kills a few people on the server and when it does theyre trapped in an infinite loop of being killed even after I put break and disable the script afterwards.

for i, player in pairs(game.Players:GetChildren()) do
	player.Character.Humanoid.Health = 0
	break
end

1 comment

0

Try addings prints around where it enables this script; that might bring you to your answer. :o

2 answers

The loop automatically breaks once it finishes going through all the players, so the break isn’t necessary.

I can’t find anything in the script that loops the loop though. Is this the whole script? If not, check if this is in a while true do loop or repeat.

Oh, and disabling the script doesn’t completely disable everything running in the script. If you have any loops running in the script and disable the script, the loop will still continue until it breaks. It shouldn’t run any more code after that though.

1 comment

0

this is the whole script, im thinking that the script is messing up because not everyone is alive only some and it kills people at different times

Putting a break inside the loop will end the loop altogether, so it will only end up killing one person. Also, you need to check if their character exists.

for i,v in pairs(game.Players:GetPlayers())do
	if v and v.Character then
		v.Character:BreakJoints()
	end
end

2 comments

0

i used this and while it killed everyone it kept killing them over and over again

0

This script wouldn't do that. What might be happening is that it gets disabled and enabled over and over again, and if this is the full script, there's no need. What you should probably do is wrap a function around it and call it every time you want to run the code.

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