Hi! My code gets no errors, but when I fire it, it tweens the first time then never continues again. I just learned tweenservice so I might be wrong about something. Thanks!
local tweenService = game:GetService('TweenService')
local part = script.Parent
while true do
wait(1)
local goal = {}
if part.Position == part.Parent.TargetOne.Position then
goal.Position = script.Parent.Parent.TargetTwo.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
elseif part.Position == part.Parent.TargetOne.Position then
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
else
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
end
end
local part = script.Parent
while true do
wait(1)
local goal = {}
if part.Position == part.Parent.TargetOne.Position then
goal.Position = script.Parent.Parent.TargetTwo.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
elseif part.Position == part.Parent.TargetTwo.Position then
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
else
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
end
end
I personally never use the position to do these kind of things, try using a normal variable instead.
My guess is that the position is 100% equal to the original part’s position.
local part = script.Parent
local CurrentPosition = part.Parent.TargetOne -- start
while true do
wait(1)
local goal = {}
if CurrentPosition == part.Parent.TargetOne then
goal.Position = script.Parent.Parent.TargetTwo.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
CurrentPosition = goal
elseif CurrentPosition == part.Parent.TargetTwo then
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
CurrentPosition = goal
else
goal.Position = script.Parent.Parent.TargetOne.Position
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
CurrentPosition = goal
end
end
The reason its not working is because youre checking for positions. You shouldnt rely on two positions being exactly the same because of floating point and a lot of other random stuff that might offset the position between two objects.
What you can do is save the last target youve tweened to or check the magnitude of two positions.