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

How To Get A Model To CFrame Near A Player?

Asked by
Donut792 216 Moderation Voter
4 years ago
Edited 4 years ago

alright so my object here is to get my model to set a few studs in front of the player and have the front face of it facing toward the player but so far all i have been able to do is have it either spawn on the player or miles away from the player while not looking at them now ive tried using lookvector to help me out here but nothing is working out how i want it to

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local Shack = ReplicatedStorage:FindFirstChild("Shack")
local debounce = false
Tool.Equipped:Connect(function()
    local ShackClone = Shack:Clone()
    ShackClone.Parent = workspace
    ShackClone.Name = "ShackBluePrint"
    while wait(.25) do
        ShackClone:SetPrimaryPartCFrame(CFrame.new(Head.Position.X + Head.CFrame.lookVector.X,Head.Position.Y,0))
        ShackClone:SetPrimaryPartCFrame(ShackClone:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(0,Head.CFrame.lookVector.Y,0),Head.Position)
    end
end)

i know the placement problem is with the first :SetPrimaryPartCFrame but with the second it somewhat works but it only moves the shack around a small bit say when the players idle animation plays and they move their head to look around

Answer this question