I know that the quality sucks, it’s because I don’t want to upload these on some other website
-
What do you want to achieve? Keep it simple and clear!
I need to be able to tween everything
Like this:
And no, it’s not calculating the distance:
-
What is the issue? Include screenshots / videos if possible!
Mine isn’t working only does this and doesn’t move the model:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked everywhere and asked for help, but it didn’t work. Also you can’t weld it because it needs to tween
My code:
local TweenService = game:GetService("TweenService")
local Type1 = script.Parent.Parent.Type1
local Type2 = script.Parent.Parent.Type2
local Type4 = script.Parent.Parent.Type4
local part = script.Parent
local onForward = true
local onBackward = false
local distanceFromType1 = part.Position - Type1.Position
local speed = 1
-- Finding Distances for Types
local function getDistanceToTarget(targetPosition)
local currentX, currentY, currentZ = part.Position.X, part.Position.Y, part.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
-- Helper function to find distance (cleaner code)
-- Setting pos of part
while true do
if _G[Type4.BrickColor.Name] == true and onForward == true then
local distanceToType2 = getDistanceToTarget(Type2.Position)
local goal = {Position = Vector3.new(part.Position.X + Type2.Position.X - part.Position.X + distanceFromType1.X, part.Position.Y + Type2.Position.Y - part.Position.Y + distanceFromType1.Y, part.Position.Z + Type2.Position.Z - part.Position.Z + distanceFromType1.Z)}
-- Adjust time based on distance (optional)
local tweenInfo = TweenInfo.new(speed, -- Adjust time based on distance
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0, -- RepeatCount (0 = no repeat)
false, -- Reverses (tween does not reverse)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
onBackward = true
onForward = false
elseif _G[Type4.BrickColor.Name] == false and onBackward == true then
local distanceToType1 = getDistanceToTarget(Type1.Position)
local goal = {Position = Vector3.new(part.Position.X + Type1.Position.X - part.Position.X + distanceFromType1.X, part.Position.Y + Type1.Position.Y - part.Position.Y + distanceFromType1.Y, part.Position.Z + Type1.Position.Z - part.Position.Z + distanceFromType1.Z)}
-- Adjust time based on distance (optional)
local tweenInfo = TweenInfo.new(speed, -- Adjust time based on distance
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0, -- RepeatCount (0 = no repeat)
false, -- Reverses (tween does not reverse)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
onForward = true
onBackward = false
end
wait(.1)
end
Thanks!