You can write your topic however you want, but you need to answer these questions:
Hi, I need the speed value of a Tween to change when a separate number value is changed. I am relatively new to scripting so bare with me here but I have tried a few different things and none of them have seemed to work. One of these methods was creating a separate tweenInformation variable for when a value changed and used a while loop which would continue to loop until the value changed, then another loop would begin with a different speed. This was problematic because when the previous tween got canceled, if the tween were to stop in a halfway position, when the other tween kicked in, it would go to the position I wanted it to but then stop at the halfway point and repeat.
Hereās the script that I tried to make so that a separate variable could control the speed.
Horrible script that I wrote:
local PumpValue = game.Workspace.CORESystems.CoolingValues.Pump1Value
local tweenService = game:GetService("TweenService")
local Part = script.Parent
local Speed = game.Workspace.CORESystems.CoolantPumps.CoolantPump1.MovingPartSpeeds
local tweeningInformation = TweenInfo.new(
Speed.Value, -- How long will the animation take?
Enum.EasingStyle.Sine, -- Animation
Enum.EasingDirection.InOut, --Easing Direction
1, -- How many times will it repeat?
true, -- Will it repeat?
0 -- Repeat delay
)
local partProperties = {
Position = Vector3.new (59.61, 18.63, 5.702)
}
local Tween = tweenService:Create(Part,tweeningInformation,partProperties)
while true do
wait()
Tween:Play()
end
Thank you so much for trying to help. I apologies if this made absolutely zero sense.
This is good info, however, I still have a problem, as when I make a new tweenInfo and it fires when the value changes, if the previous tween stops halfway, the new tween will pick up at the halfway point, go to the end position and then go back to the halfway point and repeat. Thanks for the help. Any ideas on how to fix this?
Hey, sorry to bother⦠but I am extremely new to scripting and Iām a little confused as to how I could make this part move via a for loop. Could you explain a little? Thank you so much!
Actually, before you even create the Tween, allow the script to reposition the object, or let the previous tween finish by using Tween.Completed:Wait().
local Speed = 0.05
while wait(Speed) do
script.Parent.Position += Vector3.new(0.1, 0, 0)
end
You should then be able to make it faster by lowering the āspeedā and slower by raising it. The only downside to this is the movement is less smooth than with Tweens.
This is a good idea and I tried it, but it has some issues. The way this is working is there is six buttons changing the speed of the object. So, If someone presses say two and the first one is not running, the Tween.Completed.Wait() does not seem to be working. Otherwise, this is a good idea. I think I will be going with @r_apt 's response of just bypassing the Tween completely, though it isnāt exactly what I would have liked. Thanks for your help!
This is what I am going to have to be going with. It may cause a bit of lag and wouldnāt be my first choice, but it will keep the script more organized and work better in general. Thanks for your help!
local PumpValue = game.Workspace.CORESystems.CoolingValues.Pump1Value
local tweenService = game:GetService("TweenService")
local Part = script.Parent
local Speed = game.Workspace.CORESystems.CoolantPumps.CoolantPump1.MovingPartSpeeds
local forward_tween, backward_tween do
local tween_info = TweenInfo.new(Speed.Value/2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
local start_point = {
Position = Part.Position
}
local end_point = {
Position = Vector3.new(59.61, 18.63, 5.702)
}
local function define_tweens()
backward_tween = tweenService:Create(Part,tween_info,start_point)
forward_tween = tweenService:Create(Part,tween_info,end_point)
end
define_tweens()
Speed.Changed:Connect(function(new_duration)
tween_info = TweenInfo.new(new_duration/2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
define_tweens()
end)
end
while true do
forward_tween:Play()
forward_tween.Completed:Wait()
backward_tween:Play()
backward_tween.Completed:Wait()
end
This will allow you to continue using Tweens. The speed wonāt change mid-cycle, but it should update once the currently-executing tween finishes. By breaking the tween up into start and stop tweens, you get around the issues around repeating tweens ārestartingā from the wrong position.