Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I move a model directly in-front of a player?

Asked by 5 years ago

So I am trying to move a model so that it spawns directly in-front, but a little ahead, of the player in-game. But my last few attempts at this have failed. I have used CFrame and MoveTo(), and CFrame works best, though I cannot get it working correctly, as the model doesn't always appear in-front of the player.

0
Um be more specific directly in front or something? Also if you are trying to move a model you can't because a model doesn't have a cframe because it doesn't have a position. If you would want to move it you would need to get and script the individual parts with the positions. voidofdeathfire 148 — 5y
0
Incorrect, you can use Model:MoveTo(), or use Model:SetPrimaryPartCFrame. As stated in my question. ConnorThomp 87 — 5y

1 answer

Log in to vote
1
Answered by
vissequ 105
5 years ago
Edited 5 years ago

I'm not an expert on this but I have been able to accomplish by using the lookvector of the player's humanoidrootpart's CFrame. Here is the code:

local plr = game:GetService("Players"):WaitForChild("vissequ")



while wait(4) do

local model = script:WaitForChild("Model"):Clone()

model:SetPrimaryPartCFrame(plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 12)

model.Parent = game.Workspace

end

This of course assumes the model is a child of the script. As you can see all it does is sets the location of the models primary part equal to the players location + 12 studs in front of that player (using lookvector *12).

This of course will not control the way the model is orientated, but you could do the same type of thing if you desired to control the model's orientation and not just its position.

Somebody else could probably give a better explanation, but I tested that out and it works per your request.

0
For what I am wanting to achieve this is perfect, thank you! Do you know how I would implement the orientation of the model? ConnorThomp 87 — 5y
0
Never mind, found your YouTube channel and managed to find a video that showed what I needed. There's some really helpful tutorials on there also, keep it up! ConnorThomp 87 — 5y
0
Thank you very much :) vissequ 105 — 5y
Ad

Answer this question