Hello, i wanted to make if the timer goes to 0, it will checks the bool to true, but when i test it, it doesnt work at all, heres the script.
while wait(1) do
if seconds > 0 then
seconds = seconds - 1
script.Parent.touch.SurfaceGui.timer.Text = seconds
elseif seconds <= 0 then
script.Parent.reset.Value = true
wait(5)
seconds = 30
script.Parent.touch.SurfaceGui.timer.Text = seconds
end
end
if script.Parent.reset.Value == true then
local tweenservice = game:GetService("TweenService")
local tweenpart = script.Parent.metal
local tweeninformation = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal = {Position = Vector3.new(-1.256, 5.544, -38.076)}
local lemtpd = tweenservice:Create(tweenpart,tweeninformation,tweengoal)
lemtpd:Play()
local tweenservice2 = game:GetService("TweenService")
local tweenpart2 = script.Parent.metal2
local tweeninformation2 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal2 = {Position = Vector3.new(-1.256, 5.506, -31.629)}
local lemtpd2 = tweenservice:Create(tweenpart2,tweeninformation2,tweengoal2)
lemtpd2:Play()
wait(2.5)
wait(2.5)
local tweenservice3 = game:GetService("TweenService")
local tweenpart3 = script.Parent.metal
local tweeninformation3 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal3 = {Position = Vector3.new(-1.256, 5.544, -40.714)}
local lemtpd3 = tweenservice:Create(tweenpart3,tweeninformation3,tweengoal3)
lemtpd3:Play()
local tweenservice4 = game:GetService("TweenService")
local tweenpart4 = script.Parent.metal2
local tweeninformation4 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal4 = {Position = Vector3.new(-1.256, 5.506, -28.91)}
local lemtpd4 = tweenservice:Create(tweenpart4,tweeninformation4,tweengoal4)
lemtpd4:Play()
end
Please help me.
seconds is never defined. Is that the issue?
In addition, you never break the loop, so the if will never run.
put a loop on your if it checking only 1 time!
the if statement that you write isnt in a loop so it will check only when a script is started
and yes you are using a loop above the if so it will be forever loop so it will not pass down to the check script
NOTE: explanation bad sry 
The loop seems like a countdown that is supposed to run forever, so breaking it wont really work. Probably just wrap a coroutine or spawn around it.
1 Like
Change your code to this:
coroutine.resume(coroutine.create(function()
while wait(1) do
if seconds > 0 then
seconds = seconds - 1
script.Parent.touch.SurfaceGui.timer.Text = seconds
elseif seconds <= 0 then
script.Parent.reset.Value = true
wait(5)
seconds = 30
script.Parent.touch.SurfaceGui.timer.Text = seconds
end
end
end))
while wait() do
if script.Parent.reset.Value == true then
local tweenservice = game:GetService("TweenService")
local tweenpart = script.Parent.metal
local tweeninformation = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal = {Position = Vector3.new(-1.256, 5.544, -38.076)}
local lemtpd = tweenservice:Create(tweenpart,tweeninformation,tweengoal)
lemtpd:Play()
local tweenservice2 = game:GetService("TweenService")
local tweenpart2 = script.Parent.metal2
local tweeninformation2 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal2 = {Position = Vector3.new(-1.256, 5.506, -31.629)}
local lemtpd2 = tweenservice:Create(tweenpart2,tweeninformation2,tweengoal2)
lemtpd2:Play()
wait(2.5)
wait(2.5)
local tweenservice3 = game:GetService("TweenService")
local tweenpart3 = script.Parent.metal
local tweeninformation3 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal3 = {Position = Vector3.new(-1.256, 5.544, -40.714)}
local lemtpd3 = tweenservice:Create(tweenpart3,tweeninformation3,tweengoal3)
lemtpd3:Play()
local tweenservice4 = game:GetService("TweenService")
local tweenpart4 = script.Parent.metal2
local tweeninformation4 = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweengoal4 = {Position = Vector3.new(-1.256, 5.506, -28.91)}
local lemtpd4 = tweenservice:Create(tweenpart4,tweeninformation4,tweengoal4)
lemtpd4:Play()
break
end
end
1 Like