Ok here is the issue. I cant figure out how to make my Clocktime tween wait. What I mean is when the player presses the button GUI and spams it the sun kind of stays in the same spot I would like it to go down to the next Clocktime setting then once it reaches it and you click it goes back, that way it wont spam and mess up my tween button as well.
local lighting = game.Lighting
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
if lighting.ClockTime == 15 then
local Tween = game:GetService("TweenService"):Create(lighting, TweenInfo.new(1), {
ClockTime = 16.5
})
Tween:Play()
wait(1) -- pretty much this does nothing ;/
else
local Tween = game:GetService("TweenService"):Create(lighting, TweenInfo.new(1), {
ClockTime = 15
})
Tween:Play()
wait(1) -- same with this, it does nothing
end
end)
This is the issue
(I tried doing what I did for my button but I cant get it to work ;/)
The Completed event of the Tween can be utilized in conjunction with :Wait() to make sure that the code yields until the event fires (which is when the full duration of the Tween has elapsed).
Example:
Tween:Play()
print("This will appear when the Tween has started")
Tween.Completed:Wait()
print("This will appear when the Tween has stopped")
Ah I forgot that adding a debounce would be necessary in this case to ensure that continuous clicks of the button wouldn’t activate the Tweens again until it had concluded.
Before we add the debounce, what happens in its current state can also be visualized through the Output by adding prints (such as the “This will appear when the Tween has started/stopped”) right before and after the Tween.Completed:Wait(). By continuously clicking the button, it would display that the Tween has started and stopped repeatedly, however, after the debounce is added, this should no longer occur.
Here’s what the code would look like with debounce:
(The code that handles the sound effect as well as the Tweening of the button could have the same principles applied to it as well so that it doesn’t play the sound or swap to the wrong position visually.)
local lighting = game.Lighting
local Button = script.Parent
local debounce = false
Button.MouseButton1Click:Connect(function()
if debounce == false then
debounce = true -- debounce will be set to true so that either of the Tweens are not activated until it's been completed
if lighting.ClockTime == 15 then
local Tween = game:GetService("TweenService"):Create(lighting, TweenInfo.new(1), {
ClockTime = 16.5
})
Tween:Play()
Tween.Completed:Wait()
else
local Tween = game:GetService("TweenService"):Create(lighting, TweenInfo.new(1), {
ClockTime = 15
})
Tween:Play()
Tween.Completed:Wait()
end
debounce = false -- Sets the debounce to false after the conditional statements/once any Tweens that were activated have stopped
end
end)