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

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

Asked by 6 years ago

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
0
Try addings prints around where it enables this script; that might bring you to your answer. :o TheeDeathCaster 2368 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

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 MasterKnight555 35 — 6y
Ad
Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

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
0
i used this and while it killed everyone it kept killing them over and over again MasterKnight555 35 — 6y
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. UgOsMiLy 1074 — 6y

Answer this question