#Does action before timer ends

1 messages · Page 1 of 1 (latest)

solemn heath
#

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

#

@green lake do you know why?

#

Or do you know @magic pike?

solemn heath
#

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)

hasty basin
#

hang on im lowk in a dod match

solemn heath
hasty basin
#

lemme resend this as a file

#

to read it better

solemn heath
#

Kk

#

XD

solemn heath
#

You see anything?

hasty basin
#

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?

solemn heath
#

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

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?

solemn heath
#

For what it das I guess I was following a tutorial

#

I'm new

olive river
# solemn heath local Players = game:GetService("Players") local Teams = game:GetService("Teams"...

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```

solemn heath
#

Thx

olive river
#

you have part of a debounce with RoundStarted but you don't use it properly

olive river
solemn heath
olive river
#

wait wait wait, you just blindly copy+pasted that into your script expecting it to work?

#

wtf lol

solemn heath
#

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

#

?

olive river
#

i'm not going to give you working code bro

#

that's your job to figure out

olive river
solemn heath
#

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

olive river
#

and i added ... wherever i left out parts of your code because not relevant to showing the issue

solemn heath
#

I have a weird way of learning

hasty basin
#

EVER

#

make crazy simple things and learn new things as you go along

olive river
hasty basin
#

i made the mistake of trying to make a popular game as my first ever project

solemn heath
hasty basin
#

that thing crashed and burned at 2k visits

olive river
#

bro tell me more how you passed the coding class by copying out of someone else's script Thumbs

solemn heath
#

i’m extremely low. I literally started like halfway through yesterday. I’m still trying to figure out what the code even means.

solemn heath
#

Idk how to figure it oit

hasty basin
#

make something simpler until you’re sure you understand everything

#

then move up

olive river
hasty basin
#

heck, to start maybe even write something that just teleports the player from point A to point B

olive river
#

you cannot learn to swim by starting in the middle of the ocean

solemn heath
#

It's a round started, which I thought was a pretty simple thing

#

Ok ok I get it

hasty basin
olive river
#

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

solemn heath
# hasty basin 75 lines is far from simple

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)

olive river
hasty basin
#

oh theres a fundamentals page to look at

#

that woulda been nice six months ago

solemn heath
# olive river start with, move a part

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

olive river
#

you're starting in the deep end still

#

you cannot expect to be an expert on your first day

solemn heath
#

The issue was the spelling errors and stuff

hasty basin
#

?????

olive river
solemn heath
#

like I made something capital or an N instead of an M or vice versa

olive river
solemn heath
hasty basin
#

if something’s erroring in the console that means you obviously gotta look at something

#

usually at the line of where its erroring

olive river
#

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 Thumbs

solemn heath
olive river
#

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

hasty basin
#

i keep on seeing people say “debounce” but i still have no clue what it means

solemn heath
#

like what type of thing would I want to put there to make it stop making it whenever

olive river
solemn heath
#

(Not the code)

olive river
#

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

hasty basin
#

write your own

olive river
#

in this case it's to prevent the timer from starting more than once

hasty basin
#

or even leave this for something different

olive river
#

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

solemn heath
hasty basin
#

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

solemn heath
#

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

olive river
#

and i should probably specify: if you cannot Finish a bad game, you will never Finish a great one. big difference 👍

hasty basin
#

i probably should have kept to random projects before i shot at making a big game

olive river
#

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.

olive river
solemn heath
solemn heath
#

I mean what game genre game type

olive river
#

make +1jump/sec

#

if you cannot make +1jump/sec, how do you hope to make anything else?

solemn heath
#

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

olive river
#

sure you can, why cant you

solemn heath
olive river
#

so don't be thinking i'm telling you to do things that i haven't already done myself 👍

stone token
vagrant quail
solemn heath
#

@stone token

hasty basin
#

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

stone token
solemn heath
hasty basin
hasty basin
#

stop with this script

#

its so flawed in so many ways

#

its not going to work

solemn heath
#

As in with new years and stuff

hasty basin
#

unless if i were to rewrite it entirley for you

solemn heath
hasty basin
#

which is not happening

#

learn to make something simple

#

then get to making this big game idea you have once you know how to

hasty basin