#Help with my NPC not moving to a specific location

55 messages · Page 1 of 1 (latest)

wheat patrol
#

i'm LEGIT cooked ive been trying everything to fix this so help is REALLY appreciated

what i was trying to do was the NPC is supposed to go to a location where bro would ask for coffee then waits for 30 seconds to give the player time to make said coffee. if the player does give it on time, NPC pays player then leaves and goes back to his spawnLocation before despawning, letting another NPC spawn again.

but BRO IS NOT MOVING. everything works fine its just that bro is not moving at all

#

couldnt put it in the post cuz character limit

#

Help with my NPC not moving to a specific location

karmic mason
#

any warnings or errors?

wheat patrol
#

nothing

leaden pecan
#

is this ai code

wheat patrol
leaden pecan
#

looks quite like ai to me

wheat patrol
#

i watched multiple tutorials on yt and mixed it

karmic mason
#

so you did not write this code yourself?

leaden pecan
#

"Add a proximity prompt for player interaction" sounds like chat gpt

wheat patrol
karmic mason
#

it's probably chatgpt

leaden pecan
#

maybe the code for the tutorials was written with chat GPT

#

i really dont want to believe that

karmic mason
#

it has an infinite loop in it, spawning infinite npcs at a rate of 1 per second

wheat patrol
karmic mason
#

wtf is this code ```lua
while true do
startNPCInteraction()
task.wait(1)
end

...
local function startNPCInteraction()
local npc = npcTemplate:Clone()
npc.Parent = game.Workspace
npc:SetPrimaryPartCFrame(CFrame.new(spawnLocation))
npc.PrimaryPart = npc:FindFirstChild("HumanoidRootPart")
...```

leaden pecan
#

using local function before definition?

#

that doesnt work

wheat patrol
#

a sign that im cooked

karmic mason
# leaden pecan that doesnt work

that's not the point, i put it like that for reading order. the loop calls the function, immediate next question is what is that function doing

#

and it... clones the npc? with no yield?

leaden pecan
#

its quite a strange way to structure code

#

but whats the problem

karmic mason
wide epochBOT
#

studio** You are now Level 26! **studio

leaden pecan
wheat patrol
wheat patrol
# karmic mason 1 every second?

nah what i was trying to do was if the NPC returned to its spawnLocation after NPC interaction it waits 1 second before despawning and spawning a new one

karmic mason
wheat patrol
#

but im pretty sure i done messed up big time

leaden pecan
#

new npcs wont spawn

karmic mason
#

that's before pointing out your task.delay is going to throw an error if the npc is destroyed less than 30 seconds after they are spawned, but bigger issues first y'know

leaden pecan
#

task.delay?

#

where

karmic mason
#

also if i recall, you need to move to the second waypoint following a pathfinder computeasync because the first waypoint is the current location

wheat patrol
# leaden pecan task.delay?

task.delay(30, function() if proximityPrompt.Parent then chatWithPlayer(npc, "This is taking too long. I'm out of here.") proximityPrompt:Destroy() moveToLocation(npc, spawnLocation) task.wait(1) npc:Destroy() end end) end

karmic mason
#

and then is funny if that's the case because then it immediately reaches its destination

wheat patrol
#

so i should rework the pathfinding part?

leaden pecan
#

how experienced are you with scripting

wheat patrol
#

cuz i just mainly do some simple scripts

karmic mason
# wheat patrol so i should rework the pathfinding part?

i think you should read the documentation before reworking anything. https://create.roblox.com/docs/characters/pathfinding

    -- Initially move to second waypoint (first waypoint is path start; skip it)
    nextWaypointIndex = 2

and
https://create.roblox.com/docs/reference/engine/classes/Path#GetWaypoints

The array is arranged in the order of waypoints from the path start to path end

Pathfinding is the process of moving a character along a logical path to reach a destination.

Stores the result of paths created by Class.PathfindingService:CreatePath().

wheat patrol
#

ight thanks for that

#

once im done with this i should probably stick with simple scripts

karmic mason
#

mixing chatgpt with youtube tutorials is a volatile mix. its easier to just simply learn how to code

wheat patrol
#

can i like use parts instead of coords

karmic mason
#

yes

#

there are ways to do that