You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
The Difference Between Ipairs and pairs.
What is the issue? Include screenshots / videos if possible!
I can’t seem get them.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to see the difference between them from all sources expect for this and yet I dont get it.
Please show me examples of scripts and show the difference.
ipairs iterates through arrays, while pairs iterates through both arrays and dictionaries.
local array = {1, 2, 3, 4, 5}
local dictionary = {index = "value", key = 2}
-- This won't run because `dictionary` doesn't contain any numerical indices
for i, v in ipairs(dictionary) do
print(i, v)
end
-- This will run because `array` is an array (table with numerical indices)
for i, v in ipairs(array) do
print(i, v)
end
-- This will run because `pairs` covers both arrays and dictionaries
for i, v in pairs(dictionary) do
print(i, v)
end
-- This will also run for the same reason as listed above
for i, v in pairs(array) do
print(i, v)
end
However, you no longer need to use ipairs or pairs since generalized iteration was introduced.
-- These both behave and do the same thing
for i, v in dictionary do
print(i, v)
end
for i, v in array do
print(i, v)
end
Instance:GetChildren() returns {Instance}, so you’d just want to do:
local Pointx = workspace.Pointx
local GatherChilderen = Pointx:GetChildren()
for i, v in GatherChilderen do
print(i.."="..v.Name) -- use `.Name` here
end
local Pointx = workspace.Pointx
local GatherChilderen = Pointx:GetChildren()
for i, v in GatherChilderen do
while wait(3) do
script.Parent.Position = v.Position
end
end
So, Im trying to make the part move to all the checkpoints. But the Part isn’t moving but instead going to only one spot which is Checkpoint1. how do i fix it?
local Pointx = workspace.Pointx
local GatherChilderen = Pointx:GetChildren()
for i, v in GatherChilderen do
task.wait(3) -- wait 3 seconds
script.Parent.Position = v.Position -- assign the part to this BasePart's position
end
If your intention is for this to continue forever, then you should wrap the for loop inside of a while loop:
local Pointx = workspace.Pointx
local GatherChilderen = Pointx:GetChildren()
while true do
for i, v in GatherChilderen do
task.wait(3) -- wait 3 seconds
script.Parent.Position = v.Position -- assign the part to this BasePart's position
end
task.wait() -- halt for a single frame
end