This video shows everything (Black is a part, gray is A, dark gray is B, green and red are what color it will get to activate), when the green is activated the things that are green make the part (will also need to move models and many decedents, except some of the childs) , which would be a list) move from a to b. Now as you can see in the video the tween can go at any speed (Needs to be in seconds to the other side and be at the same speed when paused and moves back or forward) . If you have any questions please ask.
Also at 1:10 it shows how it’s grouped
we can move all desc of model except those in excluded parts list
not sure if that’s the idea u wanted thoughi made a function for you
local TweenService = game:GetService("TweenService")
local model = script.Parent
local Type1 = model.Parent.Type1
local Type2 = model.Parent.Type2
local Type4 = model.Parent.Type4
local excludedParts = {"Type1", "Type2", "Type4"} -- etc
local onForward = true
local onBackward = false
local speed = 1
local currentTween = nil
local elapsedTime = 0
local function getDistanceToTarget(targetPosition)
local currentX, currentY, currentZ = model.PrimaryPart.Position.X, model.PrimaryPart.Position.Y, model.PrimaryPart.Position.Z
local targetX, targetY, targetZ = targetPosition.X, targetPosition.Y, targetPosition.Z
return math.sqrt(
(currentX - targetX) ^ 2 + (currentY - targetY) ^ 2 + (currentZ - targetZ) ^ 2
)
end
local function isExcluded(part)
return table.find(excludedParts, part.Name) ~= nil
end
local function getRelativePosition(part)
return part.Position - Type1.Position
end
local function updatePositions(alpha)
local difference = Type2.Position - Type1.Position
for _, descendant in ipairs(model:GetDescendants()) do
if descendant:IsA("BasePart") and not isExcluded(descendant) then
local relativePos = getRelativePosition(descendant)
descendant.Position = Type1.Position + relativePos + difference * alpha
end
end
end
local function createTween()
local tweenInfo = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
return TweenService:Create(model, tweenInfo, {})
end
while true do
if _G[Type4.BrickColor.Name] == true and onForward == true then
local distanceToType2 = getDistanceToTarget(Type2.Position)
if currentTween then currentTween:Cancel() end
currentTween = createTween()
currentTween:Play()
onBackward = true
onForward = false
currentTween.Completed:Connect(function() elapsedTime = speed end)
elseif _G[Type4.BrickColor.Name] == false and onBackward == true then
local distanceToType1 = getDistanceToTarget(Type1.Position)
if currentTween then currentTween:Cancel() end
currentTween = createTween()
currentTween:Play()
onForward = true
onBackward = false
currentTween.Completed:Connect(function() elapsedTime = 0 end)
end
if currentTween and currentTween.PlaybackState == Enum.PlaybackState.Playing then
elapsedTime = onBackward and elapsedTime + task.wait() or elapsedTime - task.wait()
elapsedTime = math.clamp(elapsedTime, 0, speed)
updatePositions(elapsedTime / speed)
else
task.wait(0.1)
end
end
The basically most of it, but my second problem is that if I use this twice (or more, like in the video) the end pos would be messed up. Just so you know it needs to be able to work with many movement (like in the video). Please ask questions, thanks!
could u try this?
local TweenService = game:GetService("TweenService")
local model = script.Parent
local Type1 = model.Parent.Type1
local Type2 = model.Parent.Type2
local Type4 = model.Parent.Type4
local excludedParts = {"Type1", "Type2", "Type4"} -- name of parts you want to exclude
local onForward = true
local onBackward = false
local speed = 1
local currentTween = nil
local elapsedTime = 0
local initialPositions = {}
local function getDistanceToTarget(targetPosition)
local currentX, currentY, currentZ = model.PrimaryPart.Position.X, model.PrimaryPart.Position.Y, model.PrimaryPart.Position.Z
local targetX, targetY, targetZ = targetPosition.X, targetPosition.Y, targetPosition.Z
return math.sqrt(
(currentX - targetX) ^ 2 + (currentY - targetY) ^ 2 + (currentZ - targetZ) ^ 2
)
end
local function isExcluded(part)
return table.find(excludedParts, part.Name) ~= nil
end
local function saveInitialPositions()
for _, descendant in ipairs(model:GetDescendants()) do
if descendant:IsA("BasePart") and not isExcluded(descendant) then
initialPositions[descendant] = descendant.Position - Type1.Position
end
end
end
local function updatePositions(alpha)
local difference = Type2.Position - Type1.Position
for descendant, initialPos in pairs(initialPositions) do
descendant.Position = Type1.Position + initialPos + difference * alpha
end
end
local function createTween()
local tweenInfo = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
return TweenService:Create(model, tweenInfo, {})
end
saveInitialPositions()
while true do
if _G[Type4.BrickColor.Name] == true and onForward == true then
local distanceToType2 = getDistanceToTarget(Type2.Position)
if currentTween then currentTween:Cancel() end
currentTween = createTween()
currentTween:Play()
onBackward = true
onForward = false
currentTween.Completed:Connect(function() elapsedTime = speed end)
elseif _G[Type4.BrickColor.Name] == false and onBackward == true then
local distanceToType1 = getDistanceToTarget(Type1.Position)
if currentTween then currentTween:Cancel() end
currentTween = createTween()
currentTween:Play()
onForward = true
onBackward = false
currentTween.Completed:Connect(function() elapsedTime = 0 end)
end
if currentTween and currentTween.PlaybackState == Enum.PlaybackState.Playing then
elapsedTime = onBackward and elapsedTime + task.wait() or elapsedTime - task.wait()
elapsedTime = math.clamp(elapsedTime, 0, speed)
updatePositions(elapsedTime / speed)
else
task.wait(0.1)
end
end
let me know if the issue still presist also more details would be useful
I can’t right now but I’ll test it as soon as possible. Also, thanks for taking your time and helping me!
It has some issues
In the video it resets the position on moving
Also I will probably be moving parts and models (Not just A model). Also it needs to only not move certain Children (Only certain children)
Also I think I want to use Cframe instead of position because I’ll also need to tween rotation
Please help, it’s been 4 days, please I really need help
@zenomorfs please help, pleasesssss