Ciao, I’ve been making a simulation game where you can sell to clients stuff, and even hire workers.
This continue movement of clients and workers creates a lag into the server which makes the dummy moving laggy and glitchy.
Game link if you want to see so yourself: https://www.roblox.com/games/13741148165/Culinary-Empire#!/game-instances
To make them move i use the following 2 functions, i choose which one depending on where they have to go.:
function Generale.Curve(Inizio,Fine,Intermedio,Dummy,Animazione)
--Funzioni
local function lerp(a,b,t)
return (1 - t) * a + t * b
end
--Inizia animazione
if Animazione then
Animazione:Play()
end
--Temp
local Temp = Inizio:Clone()
Temp.Name = "Temp"
Temp.Parent = Inizio.Parent
--Ciclo
for i = 0,40,1 do
--Variabili
local T = i/40
--Calcoli
local l1 = lerp(Inizio.Position,Intermedio,T)
local l2 = lerp(Intermedio,Fine.Position,T)
local quad = lerp(l1,l2,T)
local diff = l1-l2
local AngleY = math.atan2(diff.x,diff.z)*(180/math.pi)
local Aspetta = (Dummy.HumanoidRootPart.Position - quad).Magnitude / 16
--Metti la nuova posizione
Temp.Position = quad
Temp.Orientation = Vector3.new(0,AngleY,0)
--Sistema il dummy
TweenService:Create(
Dummy.HumanoidRootPart,
TweenInfo.new(Aspetta),
{CFrame = Temp.CFrame}
)
wait(Aspetta)
Dummy.HumanoidRootPart.CFrame = Temp.CFrame
end
--Finisce animazione
if Animazione then
Animazione:Stop()
end
--Sistema il dummy
TweenService:Create(
Dummy.HumanoidRootPart,
TweenInfo.new(0.1),
{CFrame = Fine.CFrame}
)
wait()
Temp:Destroy()
end
function Generale.Cammina(Fine,Dummy,Animazione)
--Variabili
local Aspetta = ((Dummy.HumanoidRootPart.Position - Fine.Position).Magnitude / 16) +0.5
--Inizia animazione
if Animazione then
Animazione:Play()
end
--Temp
local Temp = Fine:Clone()
Temp.Name = "Temp"
Temp.Parent = Fine.Parent
--Trovo la metà
local diff = Dummy.HumanoidRootPart.Position-Fine.Position
local AngleY = math.atan2(diff.x,diff.z)*(180/math.pi)
--Metti la nuova posizione
Temp.Position = Dummy.HumanoidRootPart.Position
Temp.Orientation = Vector3.new(0,AngleY,0)
--Gira
TweenService:Create(
Dummy.HumanoidRootPart,
TweenInfo.new(0.2),
{CFrame = Temp.CFrame}
):Play()
wait(0.1)
Temp:Destroy()
--Cammina
TweenService:Create(
Dummy.HumanoidRootPart,
TweenInfo.new(Aspetta,Enum.EasingStyle.Linear),
{CFrame = Fine.CFrame}
):Play()
wait(Aspetta)
--Finisce animazione
if Animazione then
Animazione:Stop()
end
end
Any tip on how to remove this lag?
I’ve tried searching around but my problem is a bit specific