Why doesnt this script work?

my goal is that when value = false then the loop breaks and when the value = true it begins

What doesn’t work about it? You should also probably do while loop.Value do instead of while true do. Additionally, you created a loop variable and don’t use it in the if statement lol.

probably exhaustion

while true do
  print("hi")
  wait() -- Don't forget to yield
end

it, just simply doesn’t work, i forgot to mention im a beginner- and sorry for the late response i did not expect anyone to reply this early- the script is a server script

Try this, but do note that you have to change the value for it to work.

local FireGun = script.Parent:WaitForChild("FireGun")
local loop = script.Parent:WaitForChild("loop")

FireGun.OnServerEvent:Connect(function(player)
       while loop.Value do
            print("hi")
      end
end)

hm, that doesnt seem to work either, im pretty sure its because of this script too


ive attached this video, just in case there are outside elements affecting it

The value isn’t being changed on the server. When you change something via explorer in a play test (or in a localscript), you’re only changing it locally. Consider using a server script to change the value to true and then try again.

ohh i did not know thats how it worked- thank you

There isn’t enough whitespace, and this may create race conditions during compiling. Add more spaces between lines to fix!

there are so many things wrong with this code.

  1. you should not be doing while loops without task.wait() unless your intentions are to crash the server
  2. secondly you should just do while script.Parent.loop.Value == true do task.wait(). the wait function is there to not crash the server