You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
GetChildren() is printing an other part when it’s suppose to print its desired part
example:
i have a part that was put in the folder called “1”
example video:
robloxapp-20210609-0158306.wmv (4.9 MB)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local targetPos = 1
local source = game.Workspace.Map.Roads.Road:GetChildren()
local npc = script.Parent
local Animation = script.Animation
local Hum = npc.AnimationController.Animator
--------
--stat--
--====--
local stat = npc.Stat
print(source[targetPos])
local walkspeed = TweenInfo.new(
source[targetPos].Position.magnitude *
stat.Walkspeed.Value / stat.Walkspeed.Value,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut
)
local health = stat.Health
-----------
--service--
-----------
local TS = game:GetService("TweenService")
local path = {}
----------
--global--
----------
local global_variable1 = nil
local global_variable2 = nil
-------------
--FUNCTIONS--
-------------
function Animate()
local loadanimation = Hum:LoadAnimation(Animation)
loadanimation:Play()
global_variable2 = loadanimation
end
function move()
--easier vector navigation.
local x = source[targetPos].Position.X
local y = source[targetPos].Position.Y
local z = source[targetPos].Position.Z
--instead of using {Position = path} you can do this.
path.Position = Vector3.new(x,y,z)
local movepos = TS:Create(
npc.PrimaryPart,
walkspeed,
{CFrame =
CFrame.new(path.Position) *
CFrame.Angles(0,math.rad(90),0)
}
)
movepos:Play()
--sets the global variable to movepos.
global_variable1 = movepos
end
Animate()
move()
-- listen for when the NPC arrives at a position
global_variable1.Completed:Connect(function(didArrive)
print("W")
if not didArrive then
error("did not arrive")
return
end
--select the next target.
targetPos += 1
-- check if there are any more targets to move to
if targetPos <= #source then
move()
else
print("Done moving!")
end
end)
Thats because its choosing from the first part of the table which will not return the part you want (unless there is only 1 part)
So i would suggest you doing this:
local source = game.Workspace.Map.Roads.Road:GetChildren()
for i,v in pairs(source) do
if v.Name == "1" then
source = v
break
end
end
What will this do is that it will run a for loop where it searches for all items in the Road folder/model until it finds a folder named “1” then it will assign the source variable as that folder and then breaks the loop
It’s printing nil. also for @zaydoudou i dont wanna do i,v pairs but if there’s any other way; can you pls tell me? if not then i’d have to do i,v pairs then. .
Ahhhhh
alright, i get it. im just gonna do for i,v pairs >:( this worked before and now it doesnt maybe because the folder before was arranged perfectly.
folder:
1 - first (this is targetted first bcuz it’s called in source[targetPos]
2 - two (now called second.)
but the folder got messed up
new folder:
2 - first(wasn’t suppose to be targetted first.)
1 - second(was suppose to be targetted first).
so i think that sums up what’s happening. i gotta make another function for i,v pairs then.
edit(it’s still in the same position as the old one. my bad i thought the folder was arranged wrong.)