I’ve used a single loop for every tweening part, but I’ve realized that it wasnt the best way to do it.
Here’s an example of it:
function move(part)
local CurrentNode = 1
while true do
if CurrentNode < #Nodes:GetChildren() then
--do tween stuff here
if ChangedSpeed == false then
CurrentNode += 1
end
end
end
eventConnection.Event:Connect(function()
move(currentPart)
end)
if anyone knows how to improve this system tell me!
other info:
-all the parts do the same route
-all the parts do different things when on a specific node
oh sorry if I didnt put much here. Basically that’s a function that moves by tween a part through each node of a nodes folder (ex. in the folder there are 10 nodes, so the part will do a tween for each node until reaching the end node (in this case node 10), then do the same again (start on node 1) and repeat)
(thanks for making me know the code review topic)
actually that cant be a fix (when speed changes the tween needs to resume), I need a way to dont use a while loop for each part (if there are 20 parts there are 20 loops, and I have 400+ parts to move)
function move(part)
while true do --I need to use a single loop for every part
--stuff
Sinse it doesnt look like ure really moving a part, just increasing a value that might represent position, this might help:
local partsMoving = {}
local partsNode = {}
local speed = 1
local maxnodes = 10
task.spawn(function()
while true do
task.wait()
for _, part in pairs(partsMoving) do
partsNode[part] += speed
if partsNode[part] > maxnodes then
partsNode[part] = partsNode[part] - maxnodes
end
end
end
end)
StartMovingPart.Event:Connect(function(part)
partsNode[part] = 1
table.insert(partsMoving, part)
end)
I’m sorry, but that cant work since the nodes have different distances and so, different time they will use to reach the next node. Actually its a good idea to use a value to say its position. but how to know the position of the place by a number (ex. totalDistance = 50, totalNodes = 10, currentPos = 25, how I know where the part might go? maybe some [Dis/Nodes] and other?)
well, I decided to do a system in a different way. Basically there is a single value that changes, then all parts find their position in the nodes, then lerping on how distance there is from the next. then when this value is changed, this is repeated again. This make sure to evitate spacing issues and bad sync for every client. But still, thank you all for the responses!