Barricade Placement Issue

So I’ve got this tool that deploys a barricade. I want to make it so that whenever or wherever the player is, and they deploy the barricade, the barricade model will spawn directly in front of them instead of depending on the direction the player is standing. I don’t really know how to do that, so help?

local fRay = Ray.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -6)))
		local hit, position = game.Workspace:FindPartOnRay(fRay, character)
		
		local ray = Ray.new(position, Vector3.new(0, 0, 0))
		local hit, pos = game.Workspace:FindPartOnRay(ray, character)
		
		local turret = game.ReplicatedStorage.Barricade:Clone()
		turret.Name = ""
		turret.Creator.Value = player
		turret:SetPrimaryPartCFrame(CFrame.new(pos + Vector3.new(0, 0, 0)))
		turret.Parent = game.Workspace

You should be able to get a placement position simply by multiplying the player’s HumanoidRootPart CFrame by another CFrame:

local placementPos = humanoidRootPart.CFrame * CFrame.new(0, 0, -3)

Might’ve gotten the wrong axis, but this should be what you’re looking for. Then, set the model’s PrimaryPart’s CFrame to that.

i’m not really sure how to implement that? this code isn’t mind, it’s just an edited free model

Get rid of everything that you have and just use this:

local placementPos = character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3)

turret:SetPrimaryPartCFrame(placementPos)
1 Like

thanks that worked. i’ve been stuck on this for the past day

1 Like