Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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()

01--// Choose Map
02 
03local Maps = {'SwordFight'}
04 
05local Number = math.random(1,#Maps)
06 
07for i,v in pairs(Maps) do
08 
09    if Number == i then
10 
11        local MapStorage = game.ReplicatedStorage.MapStorage
12 
13        local Map = MapStorage:WaitForChild(v):Clone()
14 
15        Map.Parent = game.Workspace.MapInGame
View all 36 lines...

end)

--[[ Minigames ]]-- EndMinigame.OnServerEvent:Connect(function(Player) Player:LoadCharacter() game.Workspace.MapInGame:ClearAllChildren() Player.Backpack:ClearAllChildren() end)

game.Workspace.MapInGame.ChildAdded:Connect(function(Object)

01if Object.Name == 'SwordFight' then
02 
03    local MinigameTools = ReplicatedStorage:WaitForChild('MinigameTools')
04 
05    local Sword = MinigameTools:WaitForChild('ClassicSword')
06 
07    for i,v in pairs(game.Players:GetPlayers()) do
08 
09        local Backpack = v.Backpack
10 
11        Sword:Clone().Parent = Backpack
12 
13    end
14 
15end

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

0
We can't help you without the code... Prestory 1395 — 5y
0
there is the code, u need remote events for this to work by the way, for the timer, just have a screengui with a text label and have the localscript go inside the textlabel DEVLogos 8 — 5y
0
i fixed it DEVLogos 8 — 5y

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
5 years ago

Instead of using a local variable to count the seconds i suggest using a NumberValue located in ReplicatedStorage which is edited by a ServerScript so the timer can be set every time the player dies directly from the value or when a player joins.

Ad

Answer this question