Tweenservice is better and more efficient. To use it, use its functions EXAMPLE:
TweenService:Create(RedBrick,TweenInfo,{Color3 = Color3.fromRGB(0,0,255)}):Play()
Tweenservice is better and more efficient. To use it, use its functions EXAMPLE:
TweenService:Create(RedBrick,TweenInfo,{Color3 = Color3.fromRGB(0,0,255)}):Play()
better and more efficient doesnāt really help when I dont understand it though.
What do you not understand? Iāve explained it. (I will not respond until tomorrow, so you will have to ask someone else for help now. It is my curfew.)
Youāve explained what tweens do, but not how they can be utilised.
If you can use tweenService, it is generally a very good tool to use.
Iāll try to give a fairly easy example relating to what you want. For this example we will be turning a block red over time
As for how it works you need to create a tween. And we will grab a part from workspace as an example
Firstly TweenService gets loaded
local TweenService = game:GetService("TweenService")
local part = game.Workspace.Part
Now our end goal is to call :Play() on a tween object to get it to run.
local TweenService = game:GetService("TweenService")
local part = game.Workspace.Part
local tween = nil --We need this to become a tweenObject so that the :Play method doesn't error.
tween:Play() --This is your goal
Of course right now the code above would error because we havenāt created a tweenObject. To do that we need to call TweenService:Create().
It takes 3 things as parameters
local TweenService = game:GetService("TweenService")
local part = game.Workspace.Part
local tweenInfo = nil --We will set this up later
local tween = TweenService:Create(part, tweenInfo, {Color = Color3.new(1,0,0)}) --We need this to become a tweenObject so that the :Play method doesn't error.
tween:Play() --This is your goal
Alright. Now we are almost there. We just need to go back and setup that TweenInfo. Iām just going to leave everything other than the assignment out this time because itās getting big.
local tweenInfo = TweenInfo.new(2)
That is the minimum really needed for a tweenInfo. Just stating the time. The rest of the data will be filled in with their defaults automatically.
An example of tweenInfo completely filled out
TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, true, 2)
That will create a tween that lasts for 2 seconds. Has itās speed as the quad type. Itās direction as in. It wonāt repeat. It does reverse, and it will take 2 seconds after :Play() to run.
Now we have a script that creates and runs a tween
local TweenService = game:GetService("TweenService")
local part = game.Workspace.Part
local tweenInfo = TweenInfo.new(2)
local tween = TweenService:Create(part, tweenInfo, {Color = Color3.new(1,0,0)}) --We need this to become a tweenObject so that the :Play method doesn't error.
tween:Play() --This is your goal
The code doesnāt yield after you call :Play(). Once you call play it makes it so something in the background is handling all of the data for you so your script can just continue without worrying about it. If you need to wait for a tween to end there is an event for that but thatās beyond the scope of this.
==================================================================
Now that tweens have been covered, time to focus more on your specific problem.
You want it to when you call a function change the color of lights over time.
local TweenService = game:GetService("TweenService")
local function LightsOn(WindowName, R, G, B)
local TrainParts = script.Parent:GetDescendants() --This creates an array of all parts within the main train model.
end
TweenInfo is not going to change for every tween so you can just set it up at the beginning of the function. Since tweens donāt yield it will go through the whole function without waiting so all the tweens will have started at practically the same time.
local TweenService = game:GetService("TweenService")
local function LightsOn(WindowName, R, G, B)
local tweenInfo = TweenInfo.new(2)
local TrainParts = script.Parent:GetDescendants() --This creates an array of all parts within the main train model.
for_, C in pairs(TrainParts) do
if C.Name == WindowName then
local tween = TweenService:Create(C, tweenInfo, {Color = Color3.fromRGB(R,G,B)})
tween:Play()
end
end
end
If you were to call this function again in the middle of its tween it would just override it so you donāt have to worry about waiting for it to finish before calling it again.
Wow I did not realize my post got this bigā¦ Hopefully it makes sense.
Thanks so much for taking the time to give a detailed explanation on how tween service is used. This certainly does help a little bit as to understanding how tweens work, and once Iām not tired Iāll be sure to properly test around with tweens. Thanks again!
I have. Either you skipped some of my posts or youāve ignored them.