I have two server scripts to make spawn an NPC and make it move around, yet it clones without errors but when in the workspace, it just doesn’t move…
I tried using coroutine but I’m not 100% sure how it works, just saw it on some other post here.
Any help?
spawnNpcServer (ServerScriptService)
--// Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnEvents = ReplicatedStorage:WaitForChild("spawnEvents")
local spawnNpcEvent = spawnEvents.spawnNpcEvent
--// Variables
local spawnAttributes = ReplicatedStorage.spawnAttributes
local Dummy = spawnAttributes.Dummy
local NPCfolder = game.Workspace.NPCs
--// Functions
local function cloneNpc()
local newDummy = Dummy:Clone()
newDummy.Name = "NPC"
newDummy.Parent = NPCfolder
local moveScript = spawnAttributes.Move:Clone()
moveScript.Parent = newDummy
moveScript.Enabled = true
end
local function clearNPCS()
for _, v in pairs(NPCfolder:GetDescendants()) do
if v:IsA("Model") then
v:Destroy()
end
end
end
spawnNpcEvent.OnServerEvent:Connect(function()
cloneNpc()
wait(5)
clearNPCS()
end)
Move (ReplicatedStorage)
local Dummy = script.Parent
local Humanoid = Dummy:WaitForChild("Humanoid")
local function walk()
while true do
wait(1)
Humanoid:MoveTo(Vector3.new(math.random(-50,50),0,math.random(-50,50)))
end
end
local CORO = coroutine.create(walk)
coroutine.resume(CORO)