(SOLVED) How To Make A Loop Only Happen When A Value Is True

Hello,
I am working on a camera system for my game, and I am making it so when a value is true, the power will go down. I tried this scripts below, and nothing happens. I am really blanking and any help would be appreciated.
local script:

local UserInputService = game:GetService('UserInputService')
local Camera = workspace.CurrentCamera
local Views = workspace:WaitForChild("Views")

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
local player = game:GetService('Players').LocalPlayer
local Frame = script.Parent
local deb = false
local on = false
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.Space then
		if Frame.Enabled == true then
			if Frame.back.Visible == true then
				Frame.back.Visible = false
				Frame.ViewportFrame.Visible = true
			end
			Frame.Enabled = false
			Frame.Parent.View.Enabled = true
			on = true
			game:GetService('ReplicatedStorage').OnCamera:FireServer(on)
		
		elseif Frame.Enabled == false then
			Frame.Enabled = true
			
			on = false
			game:GetService('ReplicatedStorage').OnCamera:FireServer(on)
		end
	end
end)

server script:

local value = workspace.OnCamera
local player

game.Players.PlayerAdded:Connect(function(Player)
	player = Player
end)

game:GetService('ReplicatedStorage').OnCamera.OnServerEvent:Connect(function(on)
	if on == true then
		value.Value = true
	elseif on == false then
		value.Value = false
	end
end)


while value.Value == true do
	player.PlayerGui.MainUI.TextLabel.Value.Value -= 1
	print(player.PlayerGui.MainUI.TextLabel.Value.Value)
end

Thanks in advanced!

The first value that OnServerEvent passes to you is the Player object that sent it. If you rewrite

OnServerEvent:Connect(function(on) to OnServerEvent:Connect(function(_, on)

then it should work.

isn’t this exactly what the while true do function does?

I would use that, but i have no idea where I would put that/ how to break it.

local value = true

while value do
print("the value is true")
end

This won’t work in my situation. Since the value is being changed, I can’t set it to true or else that would defeat the purpose of the script.

You would just remove the line that sets it to true.

local runService = game:GetService("RunService")

local value = ...
local power = 10000

-- every frame call this function
runService.Heartbeat:Connect(function(deltaTime)
	-- if the value is set to false exit the function early and do nothing
	if value == false then return end
	-- if value is true then subtract deltaTime from power
	power -= deltaTime
	-- print power so we can is it in the output window
	print(power)
end)

@GrumpyCools Please edit the title. It still says unsolved.

Sorry a lots, my bad. agagagaga