I’m trying to make a circular timer but it ends too fast! How would I wait for the tween to be completed first? I know I could use Tween.Completed
but I don’t know where to put it!
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local TimerRE = Remotes:WaitForChild("TimerRE")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Lighting = game:GetService("Lighting")
local DeathwishMusic = Lighting:WaitForChild("DeathWish"):WaitForChild("DeathwishMusic")
local GUI = script.Parent
local function GuiTransparency(Timer, Amount)
for i, ui in pairs(Timer:GetDescendants()) do
if ui:IsA("ImageLabel") then
ui.ImageTransparency = 1
TweenService:Create(ui, TweenInfo.new(0.5), {ImageTransparency = Amount}):Play()
elseif ui:IsA("TextLabel") then
ui.TextTransparency = 1
TweenService:Create(ui, TweenInfo.new(0.5), {TextTransparency = Amount}):Play()
end
end
end
local function StartTimer(LifeTime, TimerType)
if TimerType == nil then error("This TYPE of Timer does not exist!") return end
local tweenInfo = TweenInfo.new(LifeTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local Timer = script:WaitForChild(TimerType):Clone()
local NumberValue = Instance.new("NumberValue")
local Left = Timer.Left.Frame
local Right = Timer.Right.Frame
local NumberTitle = Timer.TimerLabel
GuiTransparency(Timer, 0)
Timer.Parent = GUI.TimerHolder
task.spawn(function()
local Tween = TweenService:Create(NumberValue, tweenInfo, {Value = 360})
Tween:Play()
for i = LifeTime, 0, -1 do
task.wait(Timer.TickRate.Value)
Timer.Tick:Play()
NumberTitle.Text = string.format("%02d", i)
end
end)
NumberValue.Changed:Connect(function(value)
value = (value % 360 + 360) % 360
Right.Rotation = math.clamp(value - 180, -180, 0)
if value > 180 then
Left.Visible = true
Left.Rotation = math.clamp(value - 360, -180, 0)
else
GuiTransparency(Timer, 1)
Left.Visible = false
end
end)
end
TimerRE.Event:Connect(function(Lifetime, Type)
StartTimer(Lifetime, Type)
end)