How to make part move above player

i am gonna fart bruh this is so annoying, do yall just want my script and yall edit it

Once again, Please do not harass DevForum users or necropost.

give me your script NOW.

local Char = script.Parent.PlayerCharacter --object value that is the palyer, i later get its rootpart (that works)

task.wait(0.05) -- doing this becuase as soon as the part is made i want it to follow

game:GetService("RunService").Heartbeat:Connect(function()
	script.Parent.CFrame:Lerp(CFrame.new(Char.Value.HumanoidRootPart.Position)*CFrame.new(0,5,0),1) --broken thingy
	
end)

Stop harrasing me or I will call ChildrenProtectionServices.

game:getservice(“Child Protection Service”)

1 Like

OK try this script …

local Char = script.Parent.PlayerCharacter --object value that is the palyer, i later get its rootpart (that works)

task.wait(0.05) -- doing this becuase as soon as the part is made i want it to follow

game:GetService("RunService").RenderStepped:Connect(function()
	script.Parent.CFrame:Lerp(Char.Value.HumanoidRootPart.CFrame*CFrame.new(0,5,0),1) --broken thingy
end)

In Pet Simulator, the pets have a delay when they follow the player, so I’m assuming that’s what your main approach is.

What we can do is keep a record of the player’s CFrame every single frame, and if the table reaches higher than 50 items or so, the parts will go to the oldest item in the table, and then delete that item.

First, we’ll make a LocalScript and define some variables. One will be the part that will follow the player, a table to store the player’s CFrame, the maximum length for the table, and the part’s offset when moving, as well as the character’s HumanoidRootPart. (Assuming that this LocalScript is inside StarterPlayer.StarterCharacterScripts)

local part = game.Workspace.Part -- Store the part that will follow the player
local playerRecord = {} -- Leave it empty for now
local maxLength = 50 -- The maximum length for the playerRecord table
local offset = CFrame.new(0,10,0) -- The offset of the part when it's moving

local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")

We’ll also grab a service. Specifically, RunService. We’ll use this to run a function every single frame. There are four types. We can run before/after the client finished a frame, or we can run before/after the game finished a Physics simulation. We’ll use RunService.PostSimulation, which runs after the Physics simulation was complete, since the player’s character only moves at those times.

We’ll also create a function for now to calculate the part following the player.

local runService = game:GetService("RunService") -- Retrieve the service first

local part = game.Workspace.Part
local playerRecord = {}
local maxLength = 50
local offset = CFrame.new(0,10,0)

local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")

local function recordPlayerMovement() -- Create a function for now
	-- We'll edit this later on
end

RunService.PostSimulation:Connect(recordPlayerMovement) -- Connect the function to this event

Inside the recordPlayerMovement function, we’ll insert the player’s CFrame into the first item in the playerRecord table using table.insert. We’ll also add a check first to see if the HumanoidRootPart does exist. If it doesn’t, stop the function and return nothing.

local runService = game:GetService("RunService")

local part = game.Workspace.Part
local playerRecord = {}
local maxLength = 50
local offset = CFrame.new(0,10,0)

local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")

local function recordPlayerMovement()
	if not humanoidRootPart then return end -- Stop the function if this condition is true
	table.insert(playerRecord, 1, humanoidRootPart.CFrame) -- Insert the CFrame into the first item in the playerRecord table
end

RunService.PostSimulation:Connect(recordPlayerMovement)

Secondly, we’ll check if the length of the playerRecord table is greater than the maxLength variable. If it isn’t, stop the function and return nothing again.

local function recordPlayerMovement()
	if not humanoidRootPart then return end
	table.insert(playerRecord, 1, humanoidRootPart.CFrame)
	if #playerRecord < maxLength then return end -- Stop the function if this condition is true
end

Lastly, we’ll set the part’s CFrame to the maxLength item in the list plus the offset variable using PVInstance:PivotTo, and then remove the item afterwards using table.remove

local function recordPlayerMovement()
	if not humanoidRootPart then return end
	table.insert(playerRecord, 1, humanoidRootPart.CFrame)
	if #playerRecord < maxLength then return end
	part:PivotTo(playerRecord[maxlength] * offset) -- Set the part's CFrame
	table.remove(playerRecord, maxLength) -- Remove the item afterwards
end

Note that this script is dependent on how fast the client’s game runs. If it runs slow, there is a noticeable delay. If it runs way fast, there is no delay noticeable.

Full Code:

local runService = game:GetService("RunService")

local part = game.Workspace.Part
local playerRecord = {}
local maxLength = 50
local offset = CFrame.new(0,10,0)

local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")

local function recordPlayerMovement()
	if not humanoidRootPart then return end
	table.insert(playerRecord, 1, humanoidRootPart.CFrame)
	if #playerRecord < maxLength then return end
	part:PivotTo(playerRecord[maxlength] * offset)
	table.remove(playerRecord, maxLength)
end

RunService.PostSimulation:Connect(recordPlayerMovement)

im NOT reading all of that, what exactly does this code do? like EXACTLY

“render step canonly be used in localscripts” or sum

it does this

local runService = game:GetService("RunService")

local part = game.Workspace.Part
local playerRecord = {}
local maxLength = 50
local offset = CFrame.new(0,10,0)

local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")

local function recordPlayerMovement()
	if not humanoidRootPart then return end
	table.insert(playerRecord, 1, humanoidRootPart.CFrame)
	if #playerRecord < maxLength then return end
	part:PivotTo(playerRecord[maxlength] * offset)
	table.remove(playerRecord, maxLength)
end

RunService.PostSimulation:Connect(recordPlayerMovement)

Oh wait change that back to Heartbeat

th

If you use the Developer Forum, please remain professional and refrain from writing comments like “im NOT reading all of that”.

are u the professional police or sum??? people can talk however they want in dev forum as long as it meets TOS
theres no rule saying “Act formal or be banned” or something

This is common practice across the DevForum. The post above you doesn’t only show you the solution but explains it as well.

im sorry, im just really tired and kinda mad cus i cant get this working…

Being formal and a likeable person on the Developer Forum is common practice.

i feel like being more goofy can make you more likable… like what if for example you had 2 friends:
1 is like “Hello friend. Would you like to play Roblox with me?”
2 is like “Hey wanna play roblox”

Who would you say is more likable?

i jsut tried this, no errors and it does nothing to the part. Reminder: The part is not anchored

Please do not go off-topic. This is against the DevForum guidelines.