Tween service teleporting instead of moving smoothly

im trying to make a aquarium with moving fishes that randomly move to points in a folder but the fishes are teleporting instead of moving and teleporting very far away randomly wich i dont intend for
video:

code:

local points = script.Parent.Parent.Points
local ts = game:GetService("TweenService")
while true do
	local waittime = math.random(0.5,1.5)
local items = points:GetChildren()
local goto = items[math.random(1, #items)]
	local tween = ts:Create(script.Parent, TweenInfo.new(waittime, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = goto.Position})
	local propertyToTween = {CFrame = CFrame.lookAt(script.Parent.CFrame.p, goto.Position)}
	local tween1 = ts:Create(script.Parent, TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.Out),propertyToTween)
	--script.Parent.CFrame = CFrame.lookAt(script.Parent.CFrame.p, goto.Position)
	tween1:Play()
	wait(0.4)
	tween:Play()
	wait(waittime)
-- same code in every fish 
end

sorry for messy code btw

explorer:
image

You can’t type this:

math.random(0.5, 1.5)

because math.random returns a whole number.
You can just do this instead to get a decimal:

math.random(50, 150)/100 -- returns a decimal between 0.5 and 1.5

teleporting a bit less but still not fixed

What’s exactly the problem? Are they staying within the aquarium?

yes they are but they are just instantly going to the points sometime

the time is incredibly fast so thats one reason to why they might be moving so fast but also use a connection instead of a while loop

local points = script.Parent.Parent.Points
local ts = game:GetService("TweenService")
local run = game:GetService("RunService")

local con con = run.RenderStepped:Connect(function()
	local waittime = math.random(30,50)/10
        local items = points:GetChildren()
        local goto = items[math.random(1, #items)]
        
        local firstTween = ts:Create(script.Parent,TweenInfo.new(1,Enum.EasingStyle.Circular,Enum.EasingDirection.Out),{CFrame = CFrame.lookAt(script.Parent.Position,goto.Position)})
        
        firstTween:Play()
        firstTween.Completed:Once(function()
          ts:Create(script.Parent,TweenInfo.new(waittime,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out),{Position = goto.Position}):Play()
        end)
        task.wait(1 + waittime)
	
-- same code in every fish 
end)

let me know if this works

causes the fish to do nothing because renderstepped is only for localscripts and the script for the fishes is a server script

image

Use Heartbeat instead.
But ideally do the tweens client-sided to save on network replication.

Also noticed the ‘con’ variable is named twice, but you probably already fixed that.

EDIT:
There’s no need for the runservice connection actually. Looping would be better like you had before.
You can use tween.Completed:Wait() to wait for the tween to end, instead of the 0.4s wait. Also changing the tween’s EasingStyle might help.

Also, you can’t run both a position and cframe tween at the same time on one instance. Keep only the cframe tween.

that fixed the teleporting but they are still just randomly teleporting very very far away and flying back to the aqarium also there is no “con” variable
new script:

local points = script.Parent.Parent.Points
local ts = game:GetService("TweenService")
while true do
	local waittime = math.random(50, 150)/100
local items = points:GetChildren()
local goto = items[math.random(1, #items)]
	local tween = ts:Create(script.Parent, TweenInfo.new(waittime, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = goto.Position})
	local propertyToTween = {CFrame = CFrame.lookAt(script.Parent.CFrame.p, goto.Position)}
	local tween1 = ts:Create(script.Parent, TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.Out),propertyToTween)
	--script.Parent.CFrame = CFrame.lookAt(script.Parent.CFrame.p, goto.Position)
	tween1:Play()
	wait(1)
	tween:Play()
	wait(waittime)
end

Yes, sorry was referencing the other person’s code.
Try this:

local points = script.Parent.Parent.Points
local ts = game:GetService("TweenService")

while true do
	-- Random number between 0.5 and 1.5
	local waittime = math.random(50, 150)/100
	local items = points:GetChildren()
	local goto = items[math.random(1, #items)]
	local propertyToTween = {CFrame = CFrame.lookAt(script.Parent.CFrame.p, goto.Position)}
	local tween = ts:Create(script.Parent, TweenInfo.new(waittime, Enum.EasingStyle.Circular, Enum.EasingDirection.Out),propertyToTween)
	tween:Play()
	task.wait(waittime)
end