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

Problem with my loop ? Second loop start when player connect

Asked by
mist0s 38
4 years ago

Hi people, I am actually doing a game with a LobbyServer and a GameServer. In the LobbyServer, there is a looped script. When a player connect to the game, it start loop. But the problem is that when a second player connect, it begin one more time the loop. I tried to correct that with a value which turn true when a player connect and the loop doesn't loop one more time. And now the problem is when a second player connect, the time goes 2 more time faster (it seem like the t = t-1 goes 2 time). Can someone help me ? Thanks for answer :D Here is the code.

local Looped = game.Workspace.Looped
Looped.Value = false
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function()
    if Looped.Value == false then
        Looped.Value = true
        StartGame()
    else
        Looped.Value = false
    end
end)

function StartGame()
local s = script.Stat
while true do
    t = 30
    repeat
        t = t-1
        s.Value = "The experience will start in "..t.." second(s)"
        wait(1)
    until t == 0
    s.Value = "Teleporting players"
    wait(0.5)
    s.Value = "Teleporting players."
    wait(0.5)
    s.Value = "Teleporting players.."
    wait(0.5)
    s.Value = "Teleporting players..."
    wait(0.5)
TeleportPlayers()
ElevatorMoving()
end
end

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago

Use a debounce. Here's an example where I would be teleporting every other player that joined the game

local debounce = false

local function Tele(plr)
    --code for starting
end

game.Players.PlayerAdded:Connect(function(plr)
    if not debounce then
        Tele(plr)
        debounce = true
    else
        debounce = false
end)
0
I already used a denounce and didn’t work mist0s 38 — 4y
Ad

Answer this question