CFrame Problem!

Hi there so i’ve been recently having a problem with cframes. As you can see in the video sometimes the strollers cframe won’t exactly go to the right position i set.

here’s the code:

function Stroller:AttachStroller(character: Model)
	local humanoid_root_part = character:WaitForChild("HumanoidRootPart")
	local humanoid = character:WaitForChild("Humanoid")
	local animator: Animator =  humanoid:WaitForChild("Animator")
	
	humanoid_root_part:SetNetworkOwner(nil)
	
	humanoid.WalkSpeed -= 5
	
	self.stroller_model.CFrame = CFrame.new(humanoid_root_part.CFrame.X - 3.5, humanoid_root_part.CFrame.Y - 1.1, humanoid_root_part.CFrame.Z)
	
	local weld_cons = Instance.new("WeldConstraint")
	weld_cons.Part0 = humanoid_root_part
	weld_cons.Part1 = self.stroller_model
	weld_cons.Parent = weld_cons.Part1
	
	self.stroller_model.CFrame *= CFrame.Angles(math.rad(-90), 0, 0)
	
	self.stroller_model.Parent = workspace
end
1 Like

Have you tried using LookVector?

1 Like

Its possible this is the issue, you could check by printing out the ending rotation

local X, Y, Z = self.stroller_model.CFrame:ToOrientation()
print(Y)

Maybe try using :ToWorldSpace()? It moves objects based on the targets cframe (npcs)

1 Like

I know your problem. You’re not assigning the rotation along with it.

function Stroller:AttachStroller(character: Model)
	local humanoid_root_part = character:WaitForChild("HumanoidRootPart")
	local humanoid = character:WaitForChild("Humanoid")
	local animator: Animator =  humanoid:WaitForChild("Animator")
	
	humanoid_root_part:SetNetworkOwner(nil)
	
	humanoid.WalkSpeed -= 5
	
	self.stroller_model.CFrame = 
        humanoid_root_part.CFrame * 
        CFrame.new(-3.5, -1.1, 0)
	
	self.stroller_model.CFrame *= CFrame.Angles(math.rad(-90), 0, 0)
	
    local weld_cons = Instance.new("WeldConstraint")
	weld_cons.Part0 = humanoid_root_part
	weld_cons.Part1 = self.stroller_model
	weld_cons.Parent = weld_cons.Part1

	self.stroller_model.Parent = workspace
end

Try this code, tell me what changes.

1 Like

OMG thank you so much man. I’ve never realise that!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.