|
| 14 Apr 2016 02:35 PM |
events.Jail.OnServerEvent:connect(function(plr, timer) wait(1) local running = true while running do wait(1) if plr and plr.TeamColor == game.Teams.Prisoner.TeamColor and timer.Value ~= 0 then timer.Value = timer.Value - 1 print(timer.Value) elseif plr and plr.TeamColor == game.Teams.Prisoner.TeamColor and timer.Value == 0 then plr.TeamColor = game.Teams.German.TeamColor wait() plr:LoadCharacter() running = false elseif (plr.TeamColor ~= game.Teams.Prisoner.TeamColor and timer.Value == 0) or timer.Value == 0 then running = false end end end)
I need a way to count down a timer whenever someone initially gets put on a team. Currently, if you get put on the team in a few times in a short period of time, or even respawned (I know why it does that), the timer will go down twice as fast as before.
Help?
|
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:24 PM |
What exactly are you trying to do?
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 03:26 PM |
When a player gets put on a team, a timer value in leaderstats (it's defined by "timer" at the top, it was passed over by the client to the server)
counts down until it hits 0, then switches a player back to the default team, and respawns them.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:33 PM |
well based on what you just said i just made a little thing. is this what you want?
switchPlayer = function(plr,time) local prevcolor = plr.TeamColor plr.TeamColor = BrickColor.new("Bright red") for i = time,0,-1 do wait(1) end plr.TeamColor = prevcolor plr:LoadCharacter() end
switchPlayer(game.Players.Player1,60)
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 03:36 PM |
What is this?
switchPlayer(game.Players.Player1,60)
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:40 PM |
well i made a function that after the player changes teams, a timer counts down then changes the player back to the default team and then resets the player
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 03:42 PM |
The problem is, the event is firing several times and continuing even after the player switched teams to default (and when they get switched back, the timer goes down twice as fast)
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:47 PM |
okay so is this what you want?
player changes team timer counts down timer hits 0 player changes back to default team player resets
?
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 03:50 PM |
pretty much except the timer is re-firing over the other one and it's counting down twice as fast...
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:58 PM |
just use a debounce and dont let the player fire the event until the timer is over. What im wondering is what exactly are you trying to do with your game. Can you explain how it works? What do the germans and prisoners do?
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 14 Apr 2016 03:59 PM |
i just reformatted your code
local running = false
events.Jail.OnServerEvent:connect(function(plr, timer) if not running then running = true while wait(1) and running do if timer.Value ~= 0 then if plr.TeamColor == game.Teams.Prisoner.TeamColor then timer.Value = timer.Value - 1 end else if plr.TeamColor == game.Teams.Prisoner.TeamColor then plr:LoadCharacter() running = false else running = false end end end running = false end end)
|
|
|
| Report Abuse |
|
|