Timer Bug, Timer resets when dead?!
Asked by
5 years ago Edited 5 years ago
I made a timer gui, and awhile ago, I thought it worked, I mean it worked how it was supposed to, but yet when you died the timer reset and the timer wasn't in sync with the other player's timers. do you know how to fix this? So far, I'm testing out screengui properties to see it that works.
the code for minigames in my server script:
local EndMinigame = ReplicatedStorage:WaitForChild('EndMinigame')
local StartMinigame = ReplicatedStorage:WaitForChild('StartMinigame')
StartMinigame.OnServerEvent:Connect(function()
03 | local Maps = { 'SwordFight' } |
05 | local Number = math.random( 1 ,#Maps) |
07 | for i,v in pairs (Maps) do |
11 | local MapStorage = game.ReplicatedStorage.MapStorage |
13 | local Map = MapStorage:WaitForChild(v):Clone() |
15 | Map.Parent = game.Workspace.MapInGame |
24 | for i,v in pairs (game.Players:GetPlayers()) do |
26 | local Character = v.Character |
28 | if Character:FindFirstChild( 'HumanoidRootPart' ) then |
30 | local X,Z = math.random(- 64 , 64 ) |
32 | Character.HumanoidRootPart.Position = Vector 3. new(X, 10 ,Z) |
end)
--[[ Minigames ]]--
EndMinigame.OnServerEvent:Connect(function(Player)
Player:LoadCharacter()
game.Workspace.MapInGame:ClearAllChildren()
Player.Backpack:ClearAllChildren()
end)
game.Workspace.MapInGame.ChildAdded:Connect(function(Object)
01 | if Object.Name = = 'SwordFight' then |
03 | local MinigameTools = ReplicatedStorage:WaitForChild( 'MinigameTools' ) |
05 | local Sword = MinigameTools:WaitForChild( 'ClassicSword' ) |
07 | for i,v in pairs (game.Players:GetPlayers()) do |
09 | local Backpack = v.Backpack |
11 | Sword:Clone().Parent = Backpack |
end)
the code for timer localscript:
local Seconds = 30
local Player = game.Players.LocalPlayer
while true do
Seconds = Seconds - 1
script.Parent.Text = 'Intermission: '..Seconds
if Seconds == 0 then
Seconds = 60
game.ReplicatedStorage.StartMinigame:FireServer()
repeat wait(1)
script.Parent.Text = 'Game In Progress: '..Seconds
Seconds = Seconds - 1
until Seconds == 0
game.ReplicatedStorage.EndMinigame:FireServer(Player)
Seconds = 30
end
wait(1)
end
NEW CODE:
local replicatedstorage = game:GetService('ReplicatedStorage')
local timer = replicatedstorage:WaitForChild('Timer').Value
local player = game.Players.LocalPlayer
while wait(1) do
if timer == 30 then
repeat wait(1)
timer = timer - 1
script.Parent.Text = 'Intermission: '..timer
until timer == 0
timer = 60
game.ReplicatedStorage.StartMinigame:FireServer()
repeat wait(1)
timer = timer -1
script.Parent.Text = 'Game In Progress: '..timer
until timer == 0
game.ReplicatedStorage.EndMinigame:FireServer(player)
end
end