When you run a script, as you know, it only runs once. If I have code that tells me how to win the game step by step, as seen below, it’ll only run a set amount of times or I’ll have to start copy and pasting the work.
print("punch them in the face!")
print("slap them!!!")
print("you can win this!")
print("punch them in the face!")
print("slap them!!!")
print("you can win this!")
If I were to do that several times, the program would have an insanely large line count for no reason at all. Now, let’s do this with a loop.
local running = true -- If I want to turn the while loop off at any point I can.
while running do
task.wait(1) -- A better alternative to wait, using it so my script doesn't exhaust,
print("punch them in the face!")
print("slap them!!!")
print("you can win this!")
end
> "punch them in the face!"
> "slap them!!!"
> "you can win this!"
This will indefinitely (meaning no defined stop, can run infinitely) loop until running is false. However, lets move the first print out of the while loop and see what happens.
local running = true -- If I want to turn the while loop off at any point I can.
print("punch them in the face!")
while running do
task.wait(1) -- A better alternative to wait, using it so my script doesn't exhaust,
print("slap them!!!")
print("you can win this!")
end
> "punch them in the face!"
> "slap them!!!"
> "you can win this!"
> "slap them!!!"
> "you can win this!"
We notice that it only prints the punch them in the face line once. This is the same issue with your program, as you’re only saying what players is once. If I told you now that I have 15 burgers, but then eat 13 and don’t tell you how would you know? We need to keep the code informed.