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

How do I make a model from ReplicatedStorage spawn in the location of a part?

I've tried making the duplicate of the model go to Workspace and then teleport it but since I am no good at scripting I can't figure it out.

1 answer

You can use CFrame, or Coordinate Frame. Set the PrimaryPart of the model to any part in it. Then insert a script into ServerScriptService with the following:

local myModel = game.ReplicatedStorage:WaitForChild("Name of Model")
local clonedModel = myModel:Clone()
local teleportPart = game.Workspace["Name of Part"]

clonedModel.PrimaryPart.CFrame = teleportPart.CFrame
clonedModel.Parent = game.Workspace

The PrimaryPart of a model is like the Main Part, and the entire model will move with it. If you don't set the PrimaryPart to a part in the model, then the model won't move, and the script won't work because PrimaryPart was mentioned, but there is no PrimaryPart.

CFrame is the Coordinate Frame of a part. So in the script, the model's coordinates were set to the part's coordinates.

I set the parent of the model to the Workspace because objects don't show in a different service, like ReplicatedStorage.

I also used the :WaitForChild function, because the script may run before the model is loaded into the game. If that occurs, then the script won't find the model because it hasn't loaded yet.

I hope the explanations and script helps!

2 comments

0

Console says that the script is not a valid nember of Workspace, is there any way to fix this?

0

You can simply insert the script into the Workspace.

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