Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited by JesseSong 2 years ago

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

Log in to vote
0
Answered by 2 years ago

Wait I Fixed It Nvm

Ad
Log in to vote
0
Answered by 2 years ago

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

Answer this question