Hi Devs so Im having trouble making the NPC move to a random seat found in the dictionary but it does spawn in the workspace it just doesnt move I wrapped it in a pcall and Im not getting any errors can someone guide me on where I made a mistake…The NPC is found in ReplicatedStorage and then cloned to the workspace every 5 seconds now to make the NPC move to a random seat is the only problem Im facing I would appreciate it if someone would guide me thank you Here’s the code for review
----//Service
----//Irretation of the Seats Dictionary
local Dummys = {
game.ReplicatedStorage.NPCs.TestDummy
}
local Seats = {
workspace.NPCSEATS.Seat,
workspace.NPCSEATS.Seat2,
workspace.NPCSEATS.Seat3
}
local DummySpawnPoint = workspace.NPCSEATS.NPCSpawnPoint.NPCSPAWN
---------------------------------------------------NPC SPAWNING CONTROLLER----------------------------------------------------------
local SpawnNPCs = function()
local RandomDummy = math.random(1,#Dummys)
local Dummy = Dummys[RandomDummy]
local ClonedDummy = Dummy:Clone()
ClonedDummy.Parent = game.Workspace
Dummy.PrimaryPart.CFrame = DummySpawnPoint.CFrame
end
local SpawnTimer = 0
while true do
wait(5)
SpawnTimer = SpawnTimer + 5
if SpawnTimer >= 30 then
SpawnTimer = 0
end
if SpawnTimer % 5 == 0 then
SpawnNPCs()
end
end
--------------------------------------------NPC MOVEMENT SECTION--------------------------------------------------------------------
local Seats = {
workspace.NPCSEATS.Seat,
workspace.NPCSEATS.Seat2,
workspace.NPCSEATS.Seat3
}
----//VARIABLES
local NPCs = game.Workspace:FindFirstChild("TestDummy")
local HRP = NPCs:WaitForChild("HumanoidRootPart")
local humanoid= NPCs:FindFirstChild("Humanoid")
local closesSeat = nil
local closestSeatDistance = math.huge
----//Irriterate through the Seats Dictionay and calculates the Distance from the Model
local success, errormessage = pcall(function()
--RandomSitSelec
local RandomSeats = math.random(1,#Seats)
closesSeat = Seats[RandomSeats]
table.remove(Seats,RandomSeats)
humanoid:MoveTo(closesSeat.Position)
humanoid.MoveToFinished:Wait()
humanoid:Sit(closesSeat)
end) --End of pcall
if success then
print("NPC INIT! ")
else
print("NPC INIT! ")
end