How do i get this to loop?

I need a little help with getting this to infinitely loop

_G.Autoreset = true
while _G.Autoreset do
wait(0.5)
game:GetService(“Players”).LocalPlayer.Character.Humanoid.Health = 0
end

Put it in a while true do loop.

That’s what he’s trying to do here, as _G.Autoreset is a boolean, but there are a few issues with the code.

Firstly, you’re setting the players health to 0 on the client. You’ll have to do this from the server, as you’ll only kill the player on their client and it’ll be buggy to others. In addition to this, _G variables are extremely slow to initiate, so you may actually be doing the loop before it can be set.

Oh. Okay. I didn’t recognize it.

Oh, okay, how do i fix these issues?

You forgot to put _G.Autoreset == true do.

_G.Autoreset = true

while _G.Autoreset == true do

wait(0.5)

game:GetService(“Players”).LocalPlayer.Character.Humanoid.Health = 0

end

Also I wouldn’t recommend using _G.

1 Like

How would i be able to do it without the g?

_G is old and can easily get exploited by exploiters.
You can use modulescripts instead.

1 Like

Okay, do i just use the same code but in a module script or do i have to make a new one?

Obviously no.
Here’s some good stuff to learn modulescripts.
https://developer.roblox.com/en-us/api-reference/class/ModuleScript

Sorry, that’s wrong. _g is just as safe from exploiters as anything else. It’s just a bad practice. Also you don’t need to put ==true in the loop, he had that right.

@MoreKedobu your code looks fine, is there a reason why you can’t just send it to 0 once or use LoadCharacter? Because it sounds like the issue might be bigger than this one snippet of code.

Also is it an localscript? That might be the problem.

1 Like

Sorry, if I am wrong, I generally never use _G so I might know it wrong.

No worries a lot of misinformation can get passed around here and it’s easy to pick stuff up that might not be true. The primary reason to avoid it is because it promotes bad code structure. It’s not a very organized way of doing things. Primarily because it first you’re keeping a bunch of unrelated stuff in one variable, then because you have to wait for all variables to initialize before you can use them. And as you already know, you can do all this stuff with module scripts to make it all cleaner

1 Like