I am using this Soldier NPC’s Pack in my game. However, when using a Script, they just stack up in one place (the Models location in ServerStorage) and don’t walk.
Here’s the Script:
for i = 1, 20 do
local soldier = game:GetService("ServerStorage"):WaitForChild("Objects"):WaitForChild("Soldier"..math.random(1, 2)):Clone() --I renamed two of the Soldiers to 'Soldier'x based on their skin tone.
soldier.Name = soldier.Name.."-"..math.random(1, 1000000)
soldier:WaitForChild("HumanoidRootPart").Position = Vector3.new(-17, 25 + i, -12)
soldier.Parent = game:GetService("Workspace"):WaitForChild("DynamicObjects")
end
You actually can. There is no errors and :WaitForChild("test"..noob), where noob is a string equal to “iamanoob”, will basically do a :WaitForChild("testiamanoob") action.
Here is updated code. You were incrementing on the Y axis, so it was just stacking up anyway. Here is the updated code, and result:
for i = 1, 20 do
local soldier = game:GetService("ServerStorage"):WaitForChild("Objects"):WaitForChild("Soldier"..math.random(1, 2)):Clone() --I renamed two of the Soldiers to 'Soldier'x based on their skin tone.
soldier.Name = soldier.Name.."-"..math.random(1, 1000000)
soldier:WaitForChild("HumanoidRootPart").Position = Vector3.new(-17 + i * 5, 25, -12)
soldier.Parent = game:GetService("Workspace"):WaitForChild("DynamicObjects")
end
It doesn’t fail… The soldiers Clone but they just don’t change their position and not move (I think that’s because NPC Script thinks that they are in the walls - there is a lot of them stacked up in one place).
Can you grab a Roblox NPC Model and test the Scripts out because the normal Positioning Scripts doesn’t seem to be working for Roblox NPC’s (I think that the whole situation is caused by active NPC Script that probably moves the Soldier).
Seem to work fine on a baseplate. There’s something wrong with your map that messes with the Roblox pathfinding navmesh I think.
Edit: I noticed there are no animations playing. Are you sure your scripts inside the soldier are running?
Maybe that is because my game uses R6 that is required to run the guns. Wait… That’s not true. When I drag a single Soldier, it waits few seconds and after that - starts to move.
Edit: That’s true. They just sit in one position and chill until dragged away with Studio move tools. The only difference between R6 and R15 is that everything works fine on R15 but doesn’t on R6.
Kinda interesting - when setting position Soldiers stacked up in one row. Now they are stacked in two rows and nothing other has changed. Here’s the most updated code:
for i = 1, 20 do
local soldier = game:GetService("ServerStorage"):WaitForChild("Objects"):WaitForChild("Soldier"..math.random(1, 2)):Clone() --I renamed two of the Soldiers to 'Soldier'x based on their skin tone.
soldier.Name = soldier.Name.."-"..math.random(1, 1000000)
soldier:SetPrimaryPartCFrame(CFrame.new(-17 + i * 5, 25, -12))
soldier.Parent = game:GetService("Workspace"):WaitForChild("DynamicObjects")
end
As someone said on devforum.roblox.com, I also tried using Model:MoveTo() but the effect was the same.
I discovered that when I change Position of any part of the Soldier’s body it just stays the same Position as it was.
The second discover is that when I deleted all Scripts and put them into the Model again, the Soldier equipped a gun. @meow_pizza
The solution is very weird. I dragged Soldiers into the Workspace and then again to the Folder in Server Storage. It made the Soldiers working (somehow).