How would I make a time change tween

Hey everyone!

I was wondering how I could make my Time change GUI tween to make it look more smooth, just cause right now its an instant swap and can be spammed.

The local script is below V

local lighting = game.Lighting
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	if lighting.ClockTime == 15 then
		lighting.ClockTime = 16.5
		
	else
		
		lighting.ClockTime = 15
	end
end)

(it changes only for the clients screen so it does not affect other players)

it would nice for the sun to tween down to the next position.

thanks if anyone can help out!

The video above shows what I want!

1 Like

You’ll want to use TweenService, something like this:

local Tween = game:GetService("TweenService"):Create(lighting, TweenInfo.new(5), {
    ClockTime = 16.5
})

Tween:Play()

The number inside the TweenInfo argument is how long you want it to take for the Tween to complete, in my case I put 5 seconds, but you can put whatever you want.

Now, if you also want to prevent it from being spammed, you can use a sort of debounce variable, setting it to false when the player switches the time, only setting to true after Tween.Completed has fired, which can be done by doing Tween.Completed:Wait()

4 Likes

Thanks man! I was able to get it to work :slight_smile:

appreciate your helping

2 Likes