What I want to achieve here is simple: Multiple tweens that span over several scripts, those of which can have their speed changed by simply changing a number value.
So far, I’ve discovered that by disabling tween scripts, changing the number value which controls the speed, then reenabling the scripts changes the speed. I’ve written a script to do this automatically, but the problem is that the tween doesn’t continue from where it left off when it’s disabled to change the value, and moves as if the position it was in when it was disabled was the starting position.
I’m asking for help to see if theres an easier roundabout way of doing this, or if theres a way to solve the issue im currently having.
Wait… are you asking for a system (apparently you have one so can you show it) that stops a tween, changes it’s speed, and then continues the tween from that point? I’m pretty sure you can just cancel the tween instead of stopping it.
Thats what I’m saying, but instead of stopping the tween it disables the script the tween belongs to.
Lets say we have a part, which is being tweened from point A to point B. While the part is in the middle of moving towards point B, I disable the script, change a value, and then reenable it. The problem I’m currently having is that once I reenable the script, the part’s tween gets “shifted” and moves past point B as it had just started moving from point A.
Hope that clarifies it.
I used to use a system like this a few years ago. All I did was cancel the current tween and create a new one. Canceling a tween does not reset the properties that were manipulated (in our case: the position). This allows you to just create a tween from the current position and have it travel towards point B with the new speed. I’ll give an example:
local TweenService = game:GetService("TweenService")
local PointA = YourPointHere -- Point A
local PointB = YourPointHere -- Point B
local PartToMove = YourPartHere -- Part to tween
local SpeedNum = YourNumberValue -- Number value
local CurrentTween -- Variable to store the current tween
-- Function to tween the part
local function TweenPart(Part, Speed, EndGoal)
if (CurrentTween ~= nil and CurrentTween.PlaybackState ~= Enum.PlaybackState.Completed) then
-- Cancel current tween
CurrentTween:Cancel()
end
-- Create new tween
CurrentTween = TweenService:Create(Part, TweenInfo.new(Speed, Enum.EasingStyle.Linear), {Position = EndGoal.Position})
-- You can change the TweenInfo and EndGoal to a CFrame value if you wish, this is just for demonstration
CurrentTween:Play() -- Play the tween
end
-- Initial movement
TweenPart(PartToMove, SpeedNum.Value, PointB)
-- Connect an event to detect when the number value is updated
SpeedNum:GetPropertyChangedSignal("Value"):Connect(function()
-- Tween the part with the new value
TweenPart(PartToMove, SpeedNum.Value, PointB)
end)
If you have any questions, let me know. Hope this helps
local model = script.Parent.Parent
local TweenService = game:GetService("TweenService")
local PointA = game.Workspace.pointa -- Point A
local PointB = game.Workspace.pointb -- Point B
local PartToMove = model.PrimaryPart -- Part to tween
local SpeedNum = game.ServerStorage.Speed -- Number value
local CurrentTween -- Variable to store the current tween
-- Function to tween the part
local function TweenPart(Part, Speed, EndGoal)
if (CurrentTween ~= nil and CurrentTween.PlaybackState ~= Enum.PlaybackState.Completed) then
-- Cancel current tween
CurrentTween:Cancel()
end
-- Create new tween
CurrentTween = TweenService:Create(Part, TweenInfo.new(Speed, Enum.EasingStyle.Linear), {Position = EndGoal.Position})
-- You can change the TweenInfo and EndGoal to a CFrame value if you wish, this is just for demonstration
CurrentTween:Play() -- Play the tween
CurrentTween.Completed:Wait()
model:SetPrimaryPartCFrame(CFrame.new(PartToMove.Position - Vector3.new(-2046, 0, 0)))
end
-- Initial movement
TweenPart(PartToMove, SpeedNum.Value, PointB)
-- Connect an event to detect when the number value is updated
SpeedNum:GetPropertyChangedSignal("Value"):Connect(function()
-- Tween the part with the new value
TweenPart(PartToMove, SpeedNum.Value, PointB)
end)
I simply copy pasted the whole thing to see if it would work. Should’ve also clarified that the part is actually a model, but in reality it’s still about moving the part since the script is located within the part and everything else in the model is welded to it.