Script cloning not working?

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)

Make sure the Move script is Script, not a LocalScript.
Because the Dummy is not a player.Character, it will not run a local script

Also, you really don’t need to store all of that in replicated storage, as you will only need the server to clone, parent, and apply script to the dummy.

It’s a script yes.

Its just in replicated storage for organization

Instead of the coroutine, why not use a while loop

while script.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 do

wait(1)
Humanoid:MoveTo(Vector3.new(math.random(-50,50),0,math.random(-50,50)))
end

Are the parts of the rig unanchored?

It’s just a regular Dummy from roblox’s animation editor

Still just standing still

word to fill

Inserted rigs are still anchored by default, make sure that you unanchored every body part.

This got it, oops!

Thank you both so much!

1 Like