Hello, I got a moving platform that is using TweenService, to make the player follow it I tried to use this local script that updates the player’s CFrame if he stands on the platform:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local LastTrainCFrame
local Function
local Function2
Function = RunService.Heartbeat:Connect(function()
--------------------------------------------------------------- CHECK PLATFORM BELOW
local RootPart = player.Character.LowerTorso
local Ignore = player.Character
local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))
local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray,Ignore)
if Hit and Hit.Name == "TrainPlateform" then -- Change "RaftTop" to whatever the moving part's name is
--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION
local Train = Hit
if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
LastTrainCFrame = Train.CFrame -- This is updated later.
end
local TrainCF = Train.CFrame
local Rel = TrainCF * LastTrainCFrame:inverse()
print(Rel)
LastTrainCFrame = Train.CFrame -- Updated here.
RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
--print("set")
else
LastTrainCFrame = nil -- Clear the value when the player gets off.
end
Function2 = player.Character.Humanoid.Died:Connect(function()
Function:Disconnect() -- Stop memory leaks
Function2:Disconnect() -- Stop memory leaks
end)
wait()
end)
yes but there is one problem this platform doesn’t just go in one direction it takes turns, like it follows multiple parts placed along the rails
and I think that body movers wouldn’t be as smooth as tween service
Before telling you what the problem is, I wanted to point out that workspace:FindPartOnRay is deprecated. Switch to workspace:Raycast() instead.
Anyways, I don’t think that setting the RootPart’s CFrame is ideal. You can make it ideal, but it will take quite a bit of calculations to do so. Instead, set the AssemblyLinearVelocity of the platform to the speed/direction it’s heading. This will create a seamless experience for the player (especially since it’s a LocalScript).
yes I’ve already seen that topic I’m even using their local script but for some reason when I try it with the tween service moving platform it keeps teleporting the player to the front of the platform
I do not have the solution but here’s 2 ideas that I’ve gotten:
Are you able to obtain the force vectors applied on the moving part? If there is a way to obtain it, perhaps you could somehow apply that force onto the players character.
You can attempt to change the frictional force value of the surfaces which may help the character stay on the platform (I doubt this will work)