Help with CFrame And rotating

Question 1
I was testing around with parts and stuff , and tried the body positions and gyros , and I wanted to make it so that the part follows the player, but for some reason it doesn’t follow the back of the player in that one specific direction.

Code

local Disabled = false
local Player = game.Players:FindFirstChild(script.Parent.Parent.Name)

if Player then
	while task.wait() do
		if Player.Character.Health ~= 0 then
			if not Disabled then
				local Pos = script.Parent.Pos.Value
				local BG = script.Parent.PrimaryPart.BodyGyro
				local BP = script.Parent.PrimaryPart.BodyPosition
				local d = Player.Character.HumanoidRootPart.Position.Y - script.Parent.PrimaryPart.Position.Y
				BP.Position = (Player.Character.HumanoidRootPart.Position + Pos) - Vector3.new(0,Player.Character.HumanoidRootPart.Size.Y/2,0) + Vector3.new(0,script.Parent.PrimaryPart.Size.Y/2,0) + Vector3.new(0,game.ServerScriptService.Systems.Pets.globalPetFloat.Value,0)
				if Player.Walking.Value == false then
					BG.CFrame = CFrame.new(script.Parent.PrimaryPart.Position, Player.Character.HumanoidRootPart.Position - Vector3.new(0, d, 0))
				else
					BG.CFrame = Player.Character.HumanoidRootPart.CFrame
				end
			else
				script.Parent:Destroy()
				break
			end
		else
			Disabled = false
		end
	end
end

BodyGyro : D:1150, ;MaxTorque: 1000000, 1000000, 100000, P: 20000

bodypos : D: 1250, maxforce: 100000, 100000, 100000, position: 0,

Question 2
how would I make the part kind of have stick to the ground like the player and when the player goes to a higher place jump right over there together with this moving script.

1 Like

First of all, in line 6, change this:

if Player.Character.Health ~= 0 then

To this:

if Player.Character.Humanoid.Health ~= 0 then

Is Player.Walking.Value a value to detect if the player’s character is moving? If so, you could just do this:

If Player.Character.Humanoid.MoveDirection.Magnitude <= 0 then

Also correct me if I am wrong, but I am pretty sure you could weld the pet to the character, and then it would solve both of your questions.

1 Like
Player.Walking.Value

is already detecting player walk, yes.
Also I don’t know what kind of welding you are talking about , but if I put a weld for the player’s character and the part it wouldn’t work and the player accompanied with this script would fly to the sky attached to the part

Okay, thanks for the feedback.

I found this video pretty useful, it may be complicated for what you are trying to do, but it is for a Pet simulator tutorial.

I would assume that is a pet system he is making, which would work , but its not exactly what I am looking for

Well, you could follow the same steps with the part, just use the code he used for the pet following.

local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

local Part = Instance.new("Part")
Part.Parent = Workspace

local function OnRenderStep()
	Part.CFrame = Character:GetPivot() * CFrame.new(0, 0, 5)
end

RunService.RenderStepped:Connect(OnRenderStep)
1 Like