Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cloned model keeps disappearing?

I'm relatively new to scripting and I tried making a script where a model from Lighting (specifically an NPC) would be cloned and placed into Workspace. I don't know if the model being an NPC has something to do with it disappearing after a second or because it has multiple parts.

wait(1)

game.Lighting.NPC:Clone().Parent = game.Workspace

7 comments

0

Why did you put it in Lighting?

0

I tried moving it to different places and changing the script according to where it is but it makes no difference.

0

Move it to SeverStorage or ReplicatedStorage.

0

I tried doing that but the same thing still happens and its frustrating...

0

Did you try something like game.Lighting:WaitForChild("NPC"):Clone().Parent = game.workspace

0

No , and I just tried it right now and it works!Thank you so much.

0

np

1 answer

When you clone a model into Workspace, you’ll never know where it spawns. Another error is you used Lighting as storage but that method is deprecated.

local npcClone = game:GetService("ServerStorage").NPC:Clone()

clone.Parent = game.Workspace

if clone:FindFirstChild"HumanoidRootPart" then
    clone.PrimaryPart = clone.HumanoidRootPart
    clone:SetPrimaryPartCFrame(CFrame.new(0, 1, 0))
end

5 comments

0

I tried using this script and the NPC spawns the same way it would as in the other script but it still keeps disappearing.Perhaps the error keeps occurring because I used a Part (named "NPC")as a parent for the actual NPC model? I'm not really sure if that affects anything.

0

Have the NPC model not parented to anything else but one of the storage services and Workspace. Don’t parent it to any part.

0

The NPC model is parented to SeverStorage but is says "NPC is not a valid member of ServerStorage."

0

But you have to set the cloned part as a variable. Parent itt to Workspace.

0

Er I don't really know how to do that. All I have right now is the NPC in ServerStorage and the script in Workspace.

This discussion is preserved as it was. New answers, comments, and votes are closed.