#Problem with cloning npc

1 messages · Page 1 of 1 (latest)

unborn furnace
#

So the issue is, im trying to get this npc to start at one point and walk to the other and then despawn, and it works decent once, but litteraly every single other time after that the prints print like normaly but you cant see the npc because its stripped of all its body parts, but what is even weirder is I printed out hwo much body parts it had in the script and it said 11 even though I was looking at it, on server and client, and it only had 4.

#

local serverStorage = game:GetService("ServerStorage")
local npcOrderModule = require(serverStorage:WaitForChild("Modules"):WaitForChild("NpcOrder"))

local npcTemp = serverStorage:WaitForChild("NpcTemplate")

local npcWaypoints = workspace:WaitForChild("NpcWaypoints")
local spawn1 = npcWaypoints:WaitForChild("Spawn1")
local spawn2 = npcWaypoints:WaitForChild("Spawn2")

local spawns = {spawn1, spawn2}
local SPAWN_MIN = 2
local SPAWN_MAX = 10

local function spawnAndWalkNPC()
    print("Spawning NPC...")

    local npc = npcTemp:Clone()

    local hrp = npc:FindFirstChild("HumanoidRootPart") or npc.PrimaryPart
    local humanoid = npc:FindFirstChildOfClass("Humanoid")

    if not hrp then
        warn("No HumanoidRootPart / PrimaryPart in NPC!")
    end
    if not humanoid then
        warn("No Humanoid in NPC!")
    end

    if not hrp or not humanoid then
        npc:Destroy()
        return
    end

    local startIndex = math.random(1, #spawns)
    local startSpawn = spawns[startIndex]
    local endSpawn = spawns[startIndex == 1 and 2 or 1]

    npc:PivotTo(startSpawn.CFrame)
    npc.Parent = workspace

    print("NPC parented to workspace")

    pcall(function()
        hrp:SetNetworkOwner(nil)
    end)

    task.wait(0.1)

    print("Moving NPC to:", endSpawn.Position)
    humanoid:MoveTo(endSpawn.Position)

    humanoid.MoveToFinished:Connect(function(reached)
        print("MoveToFinished fired, reached =", reached)
        if reached then
            npc:Destroy()
        end
    end)
end

task.spawn(function()
    while true do
        spawnAndWalkNPC()
        task.wait(math.random(SPAWN_MIN, SPAWN_MAX))
    end
end)
devout hazel
#

looks like a network ownership issue

#

prob cause youre parenting the npc to workspace before setting its pos

unborn furnace
#

what does thateven mean

unborn furnace
devout hazel
#

server owned calculates part physics, client owned is a specific players computer calculating the physics and telling the server

devout hazel
unborn furnace
devout hazel
#

order of operations

#

set owner before u parent

unborn furnace
#

it still spawns without like all its stuff

#

should i set like the network owner for the parts

#

can i even do that

devout hazel
#

set network ownership for all the parts in the npc

unborn furnace
#
  07:33:19.441  Can only call Network Ownership API on a part that is descendent of Workspace  -  Server - NpcOrderController:40```
devout hazel
#

probably isnt in workspace yet

#

make sure its in workspace first

unborn furnace
#

well yea

#

you told me to put it before that

devout hazel
#

crap

#

do you have streamingenabled

#

in worksapce

#

turn off

#

and put network ownership after

unborn furnace
#

whats that

devout hazel
#

it controls how worspace loads content

unborn furnace
#

how do i do that

devout hazel
#

its a property of workspace

unborn furnace
#

what do i set it to

devout hazel
#

try turning it off first

unborn furnace
#

that didnt work

devout hazel
#

is something wrong with the npc template

unborn furnace
#

i dont htink so ive tried everything i even imported my avatar with a plugin and that did the same thing

devout hazel
#

does anything happen then

#

any issues

unborn furnace
#

ok ok ok ok progress

#

they are spawning in with there body parts and walking

#

but they arent obviously starting at a spawn

devout hazel
#

set the primary part to hrp before pivoting it

unborn furnace
#

yea that didnt work same thign happens as before

npc.PrimaryPart = npc.HumanoidRootPart
    npc:PivotTo(startSpawn.CFrame)
    npc.Parent = workspace

    print("NPC parented to workspace")
    
    
    pcall(function()
        hrp:SetNetworkOwner(nil)
    end)```
#

oh my god

#

im so dumb

#

i think i figured ou t the issue holy shit let me test this rq

#

holy cow bro i feel so stupid i have been sitting here thinking roblox was broken

#

i forgot to anchor the spawn points and they just fell through the floor 😭

devout hazel
#

lmao happens to the best of us

unborn furnace