I have a script in ServerScriptService which spawns an NPC at a pre-designated location. That NPC then walks towards the podium to deliver a speech.
When I “Run” the game the NPC spawns at the appropriate location. However, when I select “Play Here”, the NPC spawns a few studs away from his intended location on the Z axis (which could also be X since you have no reference, but the key is it isn’t the Y axis).
Just to be clear I am selecting “Play Here” but I am not spawning near the NPC so it is not an issue with my character being too close.
Does anybody have an idea of why this might happen?
Here is how I am spawning the NPC:
local JFKspaWn = game.ReplicatedStorage.Cloneables.JFK.HumanoidRootPart
local JFK = game.ReplicatedStorage.Cloneables.JFK
local SSAgentspaWn = game.ReplicatedStorage.Cloneables.SSAgent.HumanoidRootPart
local SSAgent = game.ReplicatedStorage.Cloneables.SSAgent
function SpawnNPCs()
local newJFK = JFK:Clone()
newJFK.Parent = workspace
newJFK:MoveTo(Vector3.new(-172.606, 0.673, 6.5))
local newSSAgent = SSAgent:Clone()
newSSAgent.Parent = workspace.WalkingSSAgentsSpawnable
newSSAgent:MoveTo(Vector3.new(-174.52, 2.433, 14.632))
end
function beginNPCs()
SpawnNPCs()
game.Workspace.BindableEvents.SSAgentWalkToward:Fire()
end
beginNPCs()
game.Workspace:WaitForChild("SpawnJFK").Event:Connect(function()
beginNPCs()
end)
Your code is currently too hard to follow. You can adjust this by adding a code block to your code and adding in indents. You can add in a Lua code block by doing this:
Furthermore, you can indent your code by simply hitting the tab key. Indentation helps makes your code more readable, which is useful for when you are looking for support.
Assuming that newSSAgent is a model, MoveTo() will check for collision, so if there’s something in the way of moving it there, it’ll usually move on top, since you said that it doesn’t move on Y-axis this probably isn’t your issue but I’d suggest trying out SetPrimaryPartCFrame anyways https://www.robloxdev.com/api-reference/function/Model/SetPrimaryPartCFrame
So I started writing this post the other day at a coffee shop and my order came up and I forgot to finish and send it. My apologies. Anyway that is great advice thank you so much! A follow up question if I may, if a humanoid Spawns ON a part (not below or to the side but on top of) with CanCollide = true (and that part is a part and not terrain) is it possible for that humanoid (assuming it is being told to navigate with MoveTo which checks for collisions as you mentioned) to initiate a change of course because it is making contact with the artificial ground (i.e. carpet etc) even though it does not pose a threat to the humanoid’s trajectory?
If you are using MoveTo and the NPC is told to move onto another ground (i.e. NPC is moving in a straight line on concrete and then the carpet is halfway on that concrete), the NPC will continue moving in that direction.