Hi my game script has a few bugs. One bug is that well it repeats Intermission every second of the game it never turns off. Can you help?
01 | while true do |
02 | print ( "Intermission" ) |
03 | game.ReplicatedStorage.Cows:Clone().Parent = workspace |
04 | wait( 1 ) |
05 | print ( "Game running" ) |
06 | for _, player in next , game.Players:GetPlayers() do |
07 | if getScore(player, "Cow Clicks" ) > = highScore then |
08 | print ( "Game over" ) |
09 | local spawns = { workspace.Part 1. Position,workspace.Part 2. Position,workspace.Part 3. Position } |
10 | for i, player in ipairs (game.Players:GetChildren()) do |
11 | if player.Character and player.Character:FindFirstChild( "Torso" ) then |
12 | player.Character:MoveTo(spawns [ i ] ) |
13 | player.leaderstats [ "Cow Clicks" ] .Value = 0 |
14 | end |
15 | end |
16 | end |
17 | end |
18 | end |
Well, let break this down.
First you print, then you loop through all the players, then you use a conditional statement and print once again. After that you spawns all the players. And correct me if I am wrong but it does all that with 3 seconds, non stop. Right?
Well to fix this issue you need to do something to 'wait'
Either -Add a game mode of some type -Use a timer or count down -Add a wait
The first two work pretty much in sync together. When I say a game mode of some type I really mean a function
1 | local function GameMode 1 () |
2 | wait( 300 ) --> the round is 300 seconds long |
3 | --[[ Do other stuff ]] -- |
4 | end |
A timer would be something like this
1 | local Time = 300 --Round time is 300 seconds long and print every second |
2 |
3 | while Time > 1 do |
4 | print (Time) |
5 | wait( 1 ) |
6 | end |
The last is just a simple 'wait'
1 | wait( 300 ) |
In fact, I am pretty sure all three use a yield function, aka 'wait'
To sum it up, your main problem was there you was not doing any type of waiting between the intermission and game running.
Remember these are just three of the many solution to the problem. You could always make a if statement that represent something aka a variable 'GameOn'