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.
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.
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.
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…
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)