Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Loop Not Breaking and Giving Error About the break not being in a loop? [Solved]

So i have a script that changes a value by 0.1 until you let go, and when you let go the loop to make the value go up breaks, or it should.

Here Is The Error

Workspace.Littlebigplanet40000.StartGame:52: break statement must be inside a loop

And Here Is The Script

local UIS = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local IsPlaying = false
local SpawnNote = game.ReplicatedStorage.Remotes.SpawnNote
local InputF = game.ReplicatedStorage.Remotes.InputF
local SelectedPlayArea
local ShouldBreak
local Keybinds = {Enum.KeyCode.D,Enum.KeyCode.F,Enum.KeyCode.J,Enum.KeyCode.K}
local RunService = game:GetService("RunService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.G and IsPlaying == false then
		
		
		for i,v in pairs(game.Workspace.GameAreas:GetChildren()) do
			if v.InUse.Value == false then
				SelectedPlayArea = v
				SelectedPlayArea.InUse.Value = true
				break
			end
		end
		Camera.CameraType = "Scriptable"
		Camera.CameraSubject = SelectedPlayArea.View
		Camera.CFrame = SelectedPlayArea.View.CFrame - Vector3.new(0,0,10)
		IsPlaying = true
		UIS.InputBegan:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.Q then
				SpawnNote:InvokeServer(SelectedPlayArea,1,30)
			end
		end)
	end
end)




UIS.InputBegan:Connect(function(input,Typing)
	if Typing == false and SelectedPlayArea then
		if table.find(Keybinds,input.KeyCode) then
			while true do
				
				
				InputF:InvokeServer(table.find(Keybinds,input.KeyCode),SelectedPlayArea,"Start")
				
				UIS.InputEnded:Connect(function(input,e)
					
					if e == false and SelectedPlayArea then
						
						if table.find(Keybinds,input.KeyCode) then
							InputF:InvokeServer(table.find(Keybinds,input.KeyCode),SelectedPlayArea,"End")
							
							break 
						end
					end
						
				end)
				
				
				wait(0.1)
			end
			
		end
		
	end
end)

This is all in a local script btw

Hopefully someone can help me fix this.

2 answers

break must inside the while true do you put it in

 UIS.InputEnded:Connect(function(input,e)

 end)

this is a reason why you code wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.