1
votes

This is a pretty hard question to ask because I can't possibly fit everything into a question but I can explain the problem. My game logic/game script is essentially:

function game()
-- stuff
end

while true do
    while players < 2 do
     -- tell player to invite more players and all that jazz
    end

    if players >= 2 then
       game()
    end
end

(this is just pseudocode, I'm ignoring things like wait() and Roblox API for simplicity because the idea is still the same but I think the question is general enough for programming in general)

Now, in my 'game' function, when players are ready ( i.e aren't in a menu etc.) it will teleport all the ready players to a point where the game is. Unfortunately, since 'game()' is run all the time, the players keep getting teleported over and over and it doesn't stop. I'm not sure how to make is so that it only ever teleports them once even if 'game()' is constantly run.

Here is the code for the teleportation explained simply without needing knowledge of Roblox API:

if #ready >= 2 then -- if the players in the list 'ready' (the players that are ready to start the game) 
    print(player.Name .. " moved") -- show which player is moved
    player:MoveTo(--place where the game is)) -- actually move the player
end

The problem is that since 'game()' is being run all the time, the players are constantly moved to where the game is (making it impossible for them to move). How would I get Lua to stop moving the players after all the players are moved? I tried using a for loop but that also kept being repeated since 'game()' is being repeated. I hope this is understandable to anybody knowledgeable in Lua.

1
Can you break out of the loop after the game() call?itdoesntwork
@itdoesntwork If I use break then only 1 player would be moved.user3124306
Then mark players when they're moved and only move non-marked ones?itdoesntwork

1 Answers

2
votes

It seems to me that you want to be maintaining two lists: currently playing, and wishing to play.

I'm not sure exactly what logic you're going for (can people join an in-progress game?), but the basic idea is that you'd only run game on the list of players that wish to play, not the players currently playing.