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