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
5 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.

01local Looped = game.Workspace.Looped
02Looped.Value = false
03local Players = game:GetService("Players")
04Players.PlayerAdded:Connect(function()
05    if Looped.Value == false then
06        Looped.Value = true
07        StartGame()
08    else
09        Looped.Value = false
10    end
11end)
12 
13function StartGame()
14local s = script.Stat
15while true do
View all 33 lines...

1 answer

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

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

01local debounce = false
02 
03local function Tele(plr)
04    --code for starting
05end
06 
07game.Players.PlayerAdded:Connect(function(plr)
08    if not debounce then
09        Tele(plr)
10        debounce = true
11    else
12        debounce = false
13end)
0
I already used a denounce and didn’t work mist0s 38 — 5y
Ad

Answer this question