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

How to make a model spawn directly in front of a player?

So I'm trying to make it that if you press E, there will be a model that should spawn in front of you. I've made it spawn at the player, but I don't know how to make it spawn in front of the player.

I used SetPrimaryPartCFrame to move the model. If I increase the X or Z value it won't work as I want it to because it would only work if I look at a specific direction. So I'm looking for if there's a way I can make it spawn in front of the player regardless which direction they're looking at? Any help is appreciated!

2 comments

0

Were you using the player's position or CFrame when setting the model's CFrame?

0

I tried both

1 answer

✓ Accepted answer

-- We use the HumanoidRootPart which is a 
-- part that's located inside of the player character

-- Be sure to set this values yourself
local HumanoidRootPart;
local YourModel;

-- This will return a cframe that's infront of the player by 5 studs
local offset = CFrame.new(0,0,-5)
local InfrontOfPlayer = HumanoidRootPart.CFrame * offset

YourModel:SetPrimaryPartCFrame(InfrontOfPlayer)

1 comment

0

Thank you!

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