local tweenService = game:GetService("TweenService")
local nodes = { }
for i, v in ipairs(game.Workspace.Nodes:GetChildren()) do
table.insert(nodes, #nodes + 1, v)
end
local lastNode = nodes[#nodes]
local firstNode = nodes[1]
local lastNodePosition = lastNode.Position.X
local beforeLastNodePosition = nodes[#nodes - 1].Position.X
local distance = lastNodePosition - beforeLastNodePosition
local info = TweenInfo.new(distance.X / 5)
I’m not much of a scripter and I know this probably isn’t correct, but I can’t figure it out at all lol.
EDIT: to clarify, I want the car to go the same speed from node A to node B as it would from Node B to node C, even if node B to C is 200 studs longer
Here is the small formula that you might require, i don’t know if this is correct:
local StudsPerSecond = 1 --// Unecessary to explain?
local Distance = (Position1.Position - Position2.Position).Magnitude --// Gets the Magnitude from a position to another, to clarify, magnitude converts a vector to one number.
local TimeRequired = StudsPerSecond * Distance --// An example: if Pos2 is 1 stud far from Pos1, then TimeRequired would multiply StudsPerSecond * Distance, in this case, TimeRequired would be 1, because 1 * 1 = 1.
I hope this helps (School didn’t help me, in any way lol)
Ok. Thanks. One more thing - how do I find the position of a value “v” in a table? Like, if I loop through the table, how do I find the position of “v” in the table?
To prevent that confusion, name v “Node” instead .
EDIT: Sorry, i read very quick, you might want to insert the object in the table instead, or maybe, just maybe, i don’t know if this is going to help, but you could do something like this:
nodes[#nodes + 1] = v
But i think how you’re doing it is ok? I have never tried to use the third argument from table.insert.
local tweenService = game:GetService("TweenService")
local nodes = { }
for i, v in ipairs(game.Workspace.Nodes:GetChildren()) do
table.insert(nodes, #nodes + 1, v)
end
local lastNode = nodes[#nodes]
local firstNode = nodes[1]
for i, v in ipairs(nodes) do
local pos = nodes[table.find(nodes, v)]
local pos2 = nodes[table.find(nodes, v) + 1]
local StudsPerSecond = 0.1 --// Unecessary to explain?
local Distance = (pos.Position - pos2.Position).Magnitude --// Gets the Magnitude from a position to another, to clarify, magnitude converts a vector to one number.
local TimeRequired = StudsPerSecond * Distance --// An example: if Pos2 is 1 stud far from Pos1, then TimeRequired would multiply StudsPerSecond * Distance, in this case, TimeRequired would be 1, because 1 * 1 = 1.
local change = {Position = Vector3.new(v.Position.X, v.Position.Y, v.Position.Z), Orientation = Vector3.new(v.Orientation.X, v.Orientation.Y, v.Orientation.Z)}
local info = TweenInfo.new(TimeRequired)
local tween = tweenService:Create(script.Parent.Parent, info, change)
tween:play()
tween.Completed:Wait()
end
Instead of having to waste yours other people’s time asking if it will work, you can easily test it yourself.
By the way this is redundant:
You can just do v.Position and v.Orientation.
By the way for this case the second optional argument (sounds weird doesn’t it) is unnecessary as well. When table.insert is called with only two arguments the second one is appended to the end automatically.
Actually table.insert() has 3 arguments which are the table, position and value.
But yeah if someone uses the value as second argument then it will put the value inside the table just like how J_oystick is probably wanting (Putting in the next position)
You can use @Crazyman32’s plugin, i’m not sure how to use it myself I just found it today, but maybe that can help you roblox.com/library/645414345/Node-Map
And it’s free