Why doesnt my script work?

Hi i am having a problem with my script here is my script:

local RS = game:GetService("ReplicatedStorage")

local PathFinding = require(script:WaitForChild("PathFinding"))

local Npc = RS:WaitForChild("SecurityGuard"):Clone()

local Npc2 = game.Workspace:WaitForChild("ClassD")

local Waypoints = workspace:WaitForChild("Waypoints")

Npc.Parent = workspace

task.wait(3)
local waypoint = math.random(1, #Waypoints:GetChildren())
PathFinding.MoveTo(Npc, waypoint.Position)

And i keep getting this like dumb error:

ServerScriptService.Script:15: attempt to index number with ‘Position’ - Server - Script:15

Your waypoint is just a random number.

You should do something like this

local RS = game:GetService(“ReplicatedStorage”)

local PathFinding = require(script:WaitForChild(“PathFinding”))

local Npc = RS:WaitForChild(“SecurityGuard”):Clone()

local Npc2 = game.Workspace:WaitForChild(“ClassD”)

local Waypoints = workspace:WaitForChild(“Waypoints”)

Npc.Parent = workspace

task.wait(3)
local WaypointsTable = Waypoints:GetChildren()
local Randomwaypoint = math.random(1, #WaypointsTable)

local waypoint = WaypointsTable[Randomwaypoint]

PathFinding.MoveTo(Npc, waypoint.Position)

1 Like
local waypoint = Waypoints:GetChildren()[math.random(1, #Waypoints:GetChildren())]
1 Like