How to set position of a model relative to a player's character

I’m trying to make a model appear angled relative to the player’s position. My current attempt isn’t working out to well (the arms in particular are acting weird) and I feel like I’m not using the best method.

script.Parent.RasenganActivate.OnServerEvent:Connect(function(player)
	player.Character.Rasengan.Handle.Transparency = 0.3
	player.Character.Rasengan.Part.Transparency = 0.3
	player.Character.Humanoid.WalkSpeed = 0
	
	local narutoClone = ServerStorage.Characters.Naruto:Clone()
	narutoClone.Parent = workspace
	narutoClone.Name = "Naruto"
	narutoClone.HumanoidRootPart.Position = player.Character.HumanoidRootPart.Position + Vector3.new(5,0,-4)
	narutoClone.Head.Position = player.Character.Head.Position+ Vector3.new(5,0,-4)
	narutoClone["Left Arm"].Position = player.Character["Left Arm"].Position + Vector3.new(5,0,-4)
	narutoClone["Left Leg"].Position = player.Character["Left Leg"].Position + Vector3.new(5,0,-4)
	narutoClone["Right Arm"].Position = player.Character["Right Arm"].Position + Vector3.new(5,0,-4)
	narutoClone["Right Leg"].Position = player.Character["Right Leg"].Position + Vector3.new(5,0,-4)
	narutoClone.Torso.Position = player.Character.Torso.Position+ Vector3.new(5,0,-4)
	

Is there a better way to do this?

Should use the cframes of the parts instead of the positons.

2 Likes

So I don’t want to start a new topic but I’ve almost got this working, I am just having an issue of the position of the clone not changing relative to which way I’m facing.


local debounce = false
local ServerStorage = game:GetService("ServerStorage")

script.Parent.RasenganActivate.OnServerEvent:Connect(function(player)
	player.Character.Rasengan.Handle.Transparency = 0.3
	player.Character.Rasengan.Part.Transparency = 0.3
	player.Character.Humanoid.WalkSpeed = 0
	
	local narutoClone = ServerStorage.Characters.Naruto:Clone()
	narutoClone.Parent = workspace
	narutoClone.Name = "Naruto"
	narutoClone.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position + Vector3.new(5,0,-3), player.Character.HumanoidRootPart.CFrame.Position)
	
	script.Parent.Handle.Touched:Connect(function(hit)
		if hit.Parent ~= player.Character and hit.Parent:FindFirstChild("Humanoid") then
			if not debounce then
				debounce = true
				hit.Parent.Humanoid.Health -= 30
				wait(3)
				debounce = false
			end
		end
	end)
end)

Picture of it when I face forward on spawn:

Picture of it when I face backwards from spawn:

Call Model:SetPrimaryPartCFrame on the clone.
The parameter is the new CFrame

I won’t go into CFrame manipulation, but there is an article called “Understanding CFrames” on it

1 Like

I read up on the article and the Model:SetPrimaryPartCFrame Api and I’m still confused on how to implement that into my current code.

From what I see, you want it to be offset by Vector3.new(5, 0, -4)

If that is the case, then run
narutoClone:SetPrimaryPartCFrame(player.Character.PrimaryPart.CFrame:ToWorldSpace(CFrame.new(5, 0, -4)))
This makes its CFrame the player’s CFrame but shifted locally by the offset, so it is relative, yes.

It’s probably on another line. I’ll put it in a code block and separate the components

local newCFrame = player.Character.PrimaryPart.CFrame:ToWorldSpace(CFrame.new(5, 0, -4))
narutoClone:SetPrimaryPartCFrame(newCFrame)

It was, my apologies about that, and thank you for the help. I’m gonna go play around with that a bit and see if it resolves the issue.

I noticed through the Model:SetPrimaryPartCFrame api that it doesn’t have the same LookAt variable that CFrame.new() does, is there any other way to set it so that it looks at the player’s humanoid root part from that CFrame? The placement is correct, it’s just not looking at the character now that I don’t have that other parameter to tell it where to look at.

Yea you can.

Just add a line in between:

newCFrame = CFrame.lookAt(newCFrame.Position, player.Character.PrimaryPart.Position)
1 Like