Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with my loop ? Second loop start when player connect

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

✓ Accepted answer

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)

1 comment

0

I already used a denounce and didn’t work

This discussion is preserved as it was. New answers, comments, and votes are closed.