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

--// Choose Map

local Maps = {'SwordFight'}

local Number = math.random(1,#Maps)

for i,v in pairs(Maps) do

    if Number == i then

        local MapStorage = game.ReplicatedStorage.MapStorage

        local Map = MapStorage:WaitForChild(v):Clone()

        Map.Parent = game.Workspace.MapInGame

    end

end


--// Teleport Players

for i,v in pairs(game.Players:GetPlayers()) do

    local Character = v.Character

    if Character:FindFirstChild('HumanoidRootPart') then

        local X,Z = math.random(-64,64)

        Character.HumanoidRootPart.Position = Vector3.new(X,10,Z)

    end

end

end)

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

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

if Object.Name == 'SwordFight' then

    local MinigameTools = ReplicatedStorage:WaitForChild('MinigameTools')

    local Sword = MinigameTools:WaitForChild('ClassicSword')

    for i,v in pairs(game.Players:GetPlayers()) do

        local Backpack = v.Backpack

        Sword:Clone().Parent = Backpack

    end

end

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