Hi in my game there is a timer for us. There are enough players in the lobby just a match but for some reason before it ends, it sends the players into the match instead of after it ends, although it continues counting down for some reason and that’s on top of that, even though I added code that starts a different timer when the match actually starts it thus now overlaps where it swaps between their two counters until the one finishes... and I don’t know why or where to even start looking to fix this
#Does action before timer ends
1 messages · Page 1 of 1 (latest)
hear
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local CoreEvent = game.ReplicatedStorage:WaitForChild("CoreEvent")
local RoundStarted = false
local Break = false
local Corrupter
local function StartRound()
RoundStarted = false
CoreEvent:FireAllClients("Round", "Start", 45)
for i = 45, 0, -1 do
local NumberOfPlayers = #Players:GetChildren()
if NumberOfPlayers < 2 then
CoreEvent:FireAllClients("Round", "Clear")
Break = true
break
end
task.wait(1)
end
if Break then
return
end
RoundStarted = true
Corrupter = Players:GetPlayers()[math.random(1,#Players:GetPlayers())]
Corrupter.Team = Teams.Corrupter
Corrupter.Character:PivotTo(workspace.CorrupterSpawn.CFrame + Vector3.new(0,1,0))
for i,player in pairs(Players:GetChildren()) do
if player == Corrupter then
continue
end
player.Team = Teams.Survivors
player.Character:PivotTo(workspace.SurvivorsSpawn.CFrame + Vector3.new(0,1,0))
end
CoreEvent:FireAllClients("Round", "In Progress", 180)
for i = 180,0, -1 do
task.wait(1)
end
StartRound()
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
player.Team = game.Teams.Spectators
end)
end)
if not RoundStarted then
local NumberOfPlayers = #Players:GetPlayers()
if NumberOfPlayers > 1 then
StartRound()
end
end
end)
hang on im lowk in a dod match
XX
the weird thing im seeing here is that the round starts whenever a player joins?
well
if the round isnt started i guess
you said it continues counting down after the game starts @solemn heath
do you mean like
goes back to 180 and counts down even with nobody there?
or continues into negatives?
it sends you into the match and this still like 10 seconds left of the counter
our counter isn’t finished counting down yet and it sends you in but continues to finish the countdown even though you’re ready in the match so it sends you an early
and it’s not like it’s by a second or two it’s by like a full 10 seconds or sum
@hasty basin
hmmm
why are you looping task.wait(1) instead of task.wait(180)
@solemn heath
try that first
set the whole loop to just task.wait(180)
and whats the script that CoreEvent is for?
Which one
jeez what isn't wrong with this. the round starts whenever a player joins which can cause more than 1 timer to run at the same time ```lua
local RoundStarted = false
Players.PlayerAdded:Connect(function(player)
...
if not RoundStarted then -- if the first 45 seconds have not passed, start a timer, even if one already exists
...
if NumberOfPlayers > 1 then -- if there are 2 or more players at this stage, start 2 rounds, one for each player
StartRound()
end
end
end)
local function StartRound()
RoundStarted = false -- immediately allow more round timers to start for player #3+
for i = 45, 0, -1 do -- wait 45 seconds. 45 seconds of allowing more round timers to start when a player joins.
...
if NumberOfPlayers < 2 then
...
return -- actual result of the break
end
task.wait(1)
end
RoundStarted = true -- prevent more timers from starting finally
...
for i = 180,0, -1 do
task.wait(1)
end
StartRound() -- stack overflow error, and allow more timers to start for another 45 seconds
end```
Thx
i suggest learning what a debounce pattern is and how to use it: https://create.roblox.com/docs/scripting/debounce
you have part of a debounce with RoundStarted but you don't use it properly
you got it right the first time 👍
I put it in and it I have a lot of red lines and stuff
wot
wait wait wait, you just blindly copy+pasted that into your script expecting it to work?
wtf lol
also, I don’t know if you sent me the entire code or if that was just a part of it so unless I replace everything with it
?
read this more carefully - it is your code, i added a bunch of comments explaining what parts of it is doing
I who is going to look back at it to try and figure out what the problem was. There’s no point in learning the code if it wasn’t fixing the problem.
Sorry
and i added ... wherever i left out parts of your code because not relevant to showing the issue
I have a weird way of learning
dont ever follow tutorials
EVER
make crazy simple things and learn new things as you go along
copy+pasting code is not how you learn. it's the exact opposite of learning 
i made the mistake of trying to make a popular game as my first ever project
I was going to read with the code, changed to try and figure out why it changed it to try and figure it out
that thing crashed and burned at 2k visits
bro tell me more how you passed the coding class by copying out of someone else's script 
i’m extremely low. I literally started like halfway through yesterday. I’m still trying to figure out what the code even means.
thats gonna cause your problem
Idk how to figure it oit
bro it's like you just jumped into the middle of the ocean and are now going "bruh, ocean, i'm new plz dont drown me" and then you get drowned.
heck, to start maybe even write something that just teleports the player from point A to point B
you cannot learn to swim by starting in the middle of the ocean
75 lines is far from simple
start with, move a part
teleport a player
update text in a gui textlabel
etc
make the player jump higher
make a moving platform
make a killbrick
etc
Fair I guess but it’s not like I knew that before and I heard a lot of people saying Roblox code is easier than normal (yes I mean it’s still hard but I’ve heard people just call it easy)
learn how the pieces of a script work: https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
also, I got the general code, but I was watching a tutorial. The only issues now or whatever the tutorial got wrong and spelling errors mostly been spelling errors, which is why I copied and paste because since all I’ve been doing is having people help me fix, slight spelling errors that I didn’t notice or capitalizations or like slight little changes
"all i've been doing is having people help me fix" there's your problem bruh
you're starting in the deep end still
you cannot expect to be an expert on your first day
at the end, I continued saying small little spelling errors like a capitalization or something that I didn’t notice
The issue was the spelling errors and stuff
?????
yes spelling matters a lot in code
like I made something capital or an N instead of an M or vice versa
always review the docs http://wiki.roblox.com
I now and I don’t know how I made them all the mostly it was just capitalization
if something’s erroring in the console that means you obviously gotta look at something
usually at the line of where its erroring
in fact i'd go as far to say that if you don't know how to find stuff in the documentation, you shouldn't be writing even a single line of code yet
80% of scripting is reading code, not writing it 
out of this, what is this even trying to do like what in this is important for me to look after trying and figure out what it means or even better what is wrong with my code that makes this need to fix it
your debounce is wrong / there is none
you just allow StartRound() to be called many times
and every time it is called, a new round timer starts
even if one was already started
i keep on seeing people say “debounce” but i still have no clue what it means
what channel idea do I need to fix that?
like what type of thing would I want to put there to make it stop making it whenever
@hasty basin
in brief terms a debounce is basically like a cooldown, or for it's namesake, prevents code from rapid firing like when 2 parts are physics bouncing on each other
(Not the code)
ah alright
e.g when you walk through a nocollide part, .touched will fire rapidly, so a debounce will prevent the rapid fire into something significantly more controlled
if i were you i wouldnt look at trying to fix this code
write your own
in this case it's to prevent the timer from starting more than once
or even leave this for something different
the solution here is pretty simple, just add another debounce so startround() cannot be called more than once, like the RoundStarted variable, but one that is never disabled while a round is running, unlike RoundStarted which gets disabled for the first 45 seconds
purpose of this situation what would I want to make it stop the timer like if the player is moving type of thing obviously not that specifically that would make no sense but like what action would I want to make it start the timer in addition
heck, ive made like 5 games expecting to turn them all into real games i would release and make playable
one is still indev, 3 are scrappped till the end of time, and one puts so much stress on the server its nearly unplayable
XX
to be honest, I’m not looking to becoming the biggest Roblox game maker just the game here in there especially cause I mainly make normal games
ive made 2 complete games from scratch, one is a monster in a maze and the other is a simulator. they're not great games, but that's how you get started - by making simple, crappy games. if you cannot make a bad game, you will never make a great one 
and i should probably specify: if you cannot Finish a bad game, you will never Finish a great one. big difference 👍
i probably should have kept to random projects before i shot at making a big game
because finishing a game is not the same as how you would start one. finishing means polish, add sounds and effects to everything, thoroughly test to make sure everything works, stress test to find edge cases and rare bugs
add in badges, gamepasses, devproducts. add a bunch of art to the game like logos and banners
etc
there's quite a bit that goes into finishing a game, and you only experience that at the end of a development cycle, so it is absolutely worth sticking it out for a bad game just to get the experience of finishing something.
so i suggest starting with something exceedingly small and simple, like +1jump/sec is a perfect first project. you can finish it in a day and there's lots of little pieces that go into it
What would I make tho the only game in mind I wanna make on Roblox now and who knows how long it’ll stay like that is this specific game and most other games I can think of that I would want to make. I’ll just make an actual game instead of a Roblox one
i just told you what to make
I mean what game genre game type
make +1jump/sec
if you cannot make +1jump/sec, how do you hope to make anything else?
you can’t just start taking a bunch of random game things and putting them together to attempt to make a one game like you can’t have a duty top down farming game have a double jump
sure you can, why cant you
also for the record here's my +1jump/sec game: https://www.roblox.com/games/14238459158/Jumping-Simulator
I said a 2D top dawn game?
so don't be thinking i'm telling you to do things that i haven't already done myself 👍
just to let u know, use Players:GetPlayers() instead of Players:GetChildren()
This is a limiting thought, the whole point of game development is to not limit.
how would I know which one cause there is two
@stone token
bro ignored ALL of what we had to say💔
@solemn heath dont try to fix a script you got from a tutorial
this is like
trying to upgrade a go-kart to a full sized car
at that point, its a better idea to start over
and if you dont know how to write such a script, learn how to
u just memorise it, players:GetPlayers() is much safer
I mean there were 2 of the other ones and when I changed both it did not work so which is the problem
tis guys gonna fix the script when the second coming happens bro
I was busy
And still am
dude
stop with this script
its so flawed in so many ways
its not going to work
As in with new years and stuff
unless if i were to rewrite it entirley for you
...
which is not happening
learn to make something simple
then get to making this big game idea you have once you know how to
what?