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.
#Problem with cloning npc
1 messages · Page 1 of 1 (latest)
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)
looks like a network ownership issue
prob cause youre parenting the npc to workspace before setting its pos
what does thateven mean
how might i go about fixing it
server owned calculates part physics, client owned is a specific players computer calculating the physics and telling the server
setnetworkowner(nil)
it still spawns without like all its stuff
should i set like the network owner for the parts
can i even do that
ya you can
set network ownership for all the parts in the npc
07:33:19.441 Can only call Network Ownership API on a part that is descendent of Workspace - Server - NpcOrderController:40```
crap
do you have streamingenabled
in worksapce
turn off
and put network ownership after
whats that
it controls how worspace loads content
how do i do that
its a property of workspace
what do i set it to
try turning it off first
that didnt work
is something wrong with the npc template
i dont htink so ive tried everything i even imported my avatar with a plugin and that did the same thing
try running the script without pivoting it
does anything happen then
any issues
ok ok ok ok progress
they are spawning in with there body parts and walking
but they arent obviously starting at a spawn
set the primary part to hrp before pivoting it
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 😭
lmao happens to the best of us
thanks for the help tho man without me removing the pivot idk if i would have ever found that out 😭