How do I spawn model in front of player?

Ok so, I want to spawn model (Exactly a model, not a basepart) (let’s just call it “part”) from replicated storage in front of the player at a distance of 1 stud and at a depth of 1 stud, in this case, the model should look towards the player (For example, a part with a decal, decal should be turned towards the player)
How?

4 Likes

This is what I would do:

local newmodel = [Model]:Clone([Parent])

newmodel:SetPrimaryPartCFrame(lootAt([Player character].HumanoidRootPart.Position)

newmodel:SetPrimaryPart(Vector3.new(newmodel.PrimaryPart.X + 1, newmodel.PrimaryPart.Y, newmodel.PrimaryPart.Z))
1 Like

Use CFrames, First set it to (0,0,-2) in front of the player, then set the orientation to face the player!

2 Likes
local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")
local model = repstorage:WaitForChild("Model")

task.wait(5)
local modelclone = model:Clone()
modelclone.Parent = workspace
modelclone.CFrame = humroot.CFrame + CFrame.new(0, 1, 1) --change the components of this cframe value to move the model
modelclone.Orientation = humroot.Orientation - Vector3.new(0, 0, 180) --change the components of this vector3 value to rotate the model
1 Like
local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")
local model = repstorage:WaitForChild("Model")

task.wait(5)
local modelclone = model:Clone()
modelclone.Parent = workspace
modelclone:MoveTo(humroot.Position + Vector3.new(0, 1, 1))

I just realised it’s a model which don’t have orientation, cframe, position properties etc. instead make use of the “MoveTo()” function like in the above.

Model’s always looking in the same direction

Oh right, you wanted orientation too, sorry this post is a little old.

local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")
local model = repstorage:WaitForChild("Model")

task.wait(5)
local modelclone = model:Clone()
modelclone.Parent = workspace
modelclone:SetPrimaryPartCFrame(humroot.CFrame + CFrame.new(0, 1, 1))

https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame
Is used instead, make sure the “Model” instance has a primary part otherwise this won’t work.

image

You can set a primary part by clicking on the empty box besides “PrimaryPart” and then clicking on any of the part instances which are a descendant of the model itself.

Once again, invalid argument #2 (Vector3 expected, got CFrame)

local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")
local model = repstorage:WaitForChild("Model")

task.wait(5)
local modelclone = model:Clone()
modelclone.Parent = workspace
modelclone:SetPrimaryPartCFrame(humroot.CFrame)

That’s a really weird error considering only CFrame values are being used but try the above.

1 Like

Uhh… “Unable to cast Vector3 to CoordinateFrame”

I think you may have tried before I edited it.

It kinda works, but model spawns… “inside” the player

Nah, you know, i just weld everything to one thing and stuff, it’ll be much easier than using a model
But thanks anyway

local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")
local model = repstorage:WaitForChild("Model")

task.wait(5)
local modelclone = model:Clone()
modelclone.Parent = workspace
modelclone:SetPrimaryPartCFrame(humroot.CFrame)
modelclone:TranslateBy(Vector3.new(5, 0, 5))

Have a whirl with this, I believe it will work how you intend. You may need to change “5” to accommodate smaller/larger models.

you cannot do cframe + cframe… you can only multiply cframes to add them

Eh, good enough, thanks. . . . .

I’m aware of this, multiplying the CFrame by a scale wouldn’t produce the desired result anyway.

No problem, you may want to change it to Vector3.new(x, 0, 0) or Vector3.new(0, 0, x) to only shift the model along one axis according to its current orientation.

Yeah, logically . . . . . . . .