How can I make this pet always facing fowards?

Hello,

So I am trying to make this pet system where you can spawn a pet that stays on ur shoulder. I want the pet to always spawn facing towards the way your character is facing but not sure how I can do this. I have a script that spawns the pet and stuff but it does not change the angel to stright ahead.

Code:

local function petAddShoulder(pet, plr, dataStore)
	local success, errormessage pcall(function()
		print("ff")
		local petownership = dataStore:GetAsync("User_"..plr.UserId)
		print("fffff")
		if petownership == true then
			if not plr.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild(pet) then
				for i,v in pairs(game.ServerStorage.Pets:GetChildren()) do
					if plr.Character.HumanoidRootPart:FindFirstChild(v.Name) then
						plr.Character.HumanoidRootPart:FindFirstChild(v.Name):Destroy()
					end
				end
				
			local clone = game.ServerStorage.Pets:FindFirstChild(pet):Clone()
			clone.Parent = plr.Character:FindFirstChild("HumanoidRootPart")
			local constraints = Instance.new("WeldConstraint", plr.Character:FindFirstChild("HumanoidRootPart"))
			constraints.Part0 = clone
			constraints.Part1 = plr.Character:FindFirstChild("HumanoidRootPart")
			clone.Position = plr.Character:FindFirstChild("HumanoidRootPart").Position + Vector3.new(-1.5, 3, 3)
			else
				for i,v in pairs(game.ServerStorage.Pets:GetChildren()) do
					if plr.Character.HumanoidRootPart:FindFirstChild(v.Name) then
						plr.Character.HumanoidRootPart:FindFirstChild(v.Name):Destroy()
					end
				end
				plr.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild(pet):Destroy()
					local clone = game.ServerStorage.Pets:FindFirstChild(pet):Clone()
					clone.Parent = plr.Character:FindFirstChild("HumanoidRootPart")
					local constraints = Instance.new("WeldConstraint", plr.Character:FindFirstChild("HumanoidRootPart"))
					constraints.Part0 = clone
					constraints.Part1 = plr.Character:FindFirstChild("HumanoidRootPart")
					clone.Position = plr.Character:FindFirstChild("HumanoidRootPart").Position + Vector3.new(-1.5, 3, 3)
			end
		end
	end)
end

Couldn’t you just use HumanoidRootPart.LookVector to set the pets primary cframe?
Note: You could use attachments to set the WorldCFrame for the pet, this also gives the opportunity to create floating effects and etc.

1 Like

Did not affect anything when I used LookVector.

Is the pet inside a group or Is it apart?

  • Are you able to send your explorer view of the pet folder?

Yea sure. Not sure how it will affect anything but here:

image

The script clones the pet and then puts it in the character.

1 Like

Have you tried using attachments to validate its position?

I don’t really see how I could use attatchments for this??

1 Like

As noted before, I think this is a much better way to approach this.

  • Especially when it provides a lot of customization.

Welds are similar the same as attachments @deOrcus as said. That’s why they are used within humanoid accessories to properly position hats and stuff.

2 Likes

I don’t think you get what I am trying to do. When you face forwards it faces fowards like I want but when you turn a bit it changes where it is cloned.

image
image

How does that fix the issue I am having at all??

Are you trying to make it follow instead of attached? I don’t think you stated this in your post.

1 Like

No. I just want it to face forward and stay on the shoulder. It does not follow you just stay on ur shoulder. Like one of them shoulder pets but I want it in the air a bit not on the shoulder.

I really am not sure how to make this more clear…

Non the less, If you use a loop to make the pet follow it tweened whilst setting its cframe to an attachment.

Make sure, the part is not anchored.

function changePosition(position, root, pet)
  local cframe = CFrame.new(position, position + root.CFrame.LookVector)
  pet.Position = cframe;
end

changePosition(Vector3.new(0, 0, 0), humanoidRootPart, petInstance)

The part being anchored will not affect anything? I want the dam pet to be face forwards so this will not affect anything.

By the way it is not.

Yes, it will, your code is welding it. If the part is anchored it simply can not move no matter what. [ANCHORED]

That will not make it at the side though will it?? I want it to be near the shoulder of the user above a little. This will not do that will it??