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

How Can I Stop Loop?

Asked by 9 years ago

I made radio. To use it you have to type r/ . And when I type word all 11 labels in gui repeats same word. Here is lua:

local lineNum = 1

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        if msg:sub(1,2) == "r/" then
            if lineNum == 1 then
                game.Workspace.RadioLines.L1.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1
            end
            if lineNum == 2 then
                game.Workspace.RadioLines.L2.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1
            end
            if lineNum == 3 then
                game.Workspace.RadioLines.L3.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 4 then
                game.Workspace.RadioLines.L4.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 5 then
                game.Workspace.RadioLines.L5.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 6 then
                game.Workspace.RadioLines.L6.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1
            end
            if lineNum == 7 then
                game.Workspace.RadioLines.L7.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 8 then
                game.Workspace.RadioLines.L8.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 9 then
                game.Workspace.RadioLines.L9.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 10 then
                game.Workspace.RadioLines.L10.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 11 then
                game.Workspace.RadioLines.L11.Value = player.Name ..": ".. msg:sub(3)
                lineNum = lineNum + 1 
            end
            if lineNum == 12 then
                game.Workspace.RadioLines.L1.Value = player.Name ..": ".. msg:sub(3)
                lineNum = 1
            end
        end
    end)
end)

2 answers

Log in to vote
0
Answered by 9 years ago

Figured out! Just add return 0 to stop it like in other programming languages.

Ad
Log in to vote
0
Answered by 9 years ago

No. Above is wrong. Return is used for different reasons. Use the "Break"command. For more info on the break command go to here... http://wiki.roblox.com/index.php?title=Break#Break

0
But everything works great with return. Sorry nothing gonna happen with break. vincius0000 0 — 9y

Answer this question