How to make smooth moving platforms for players to move on | Avoid glitching out of players from the moving platform

Trying to make a smooth moving platform for my obby that moves players on it.

Tutorial Followed:

The problem I am facing that even if the ray is detecting the moving platform, sometimes or frequently the player is glitching out from the platform, can’t figure out why

The Local Script I am Using:

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer

local RunService = game:GetService('RunService')

local PlayerChar = Player.CharacterAdded:Wait()
local RootPart = Player.Character:FindFirstChild("LowerTorso")

local LastCFrame

local Function, Function2, Function3

Function2 = Players.PlayerRemoving:Connect(function(PlayerLeft)
	if PlayerLeft == Player then
		Function:Disconnect()
		Function2:Disconnect()
		Function3:Disconnect()
	end
end)

Function = RunService.Heartbeat:Connect(function()
	
	if PlayerChar and RootPart then
		
		local RayParams = RaycastParams.new()
		RayParams.IgnoreWater = true
		RayParams.FilterDescendantsInstances = {PlayerChar}

		local RayCast = workspace:Raycast(RootPart.CFrame.Position, Vector3.new(0,-10,0), RayParams)
		if not RayCast then
			return
		end		
		
		local Hit = RayCast.Instance
		
		print(Hit, PlayerChar.Humanoid.Jump)
		
		if Hit and Hit.Name == "Moving" and PlayerChar.Humanoid.Jump == false then

			local Platform = Hit

			if LastCFrame == nil then
				LastCFrame = Platform.CFrame
			end

			local PlatformCF = Platform.CFrame 
			local Rel = PlatformCF * LastCFrame:inverse()
			LastCFrame = Platform.CFrame
			RootPart.CFrame = Rel * RootPart.CFrame

		else
			LastCFrame = nil 
		end
		
	else
		
		PlayerChar = Player.CharacterAdded:Wait()
		RootPart = Player.Character:FindFirstChild("LowerTorso")
		
	end

	Function3 = Player.Character.Humanoid.Died:Connect(function()
		PlayerChar = Player.CharacterAdded:Wait()
		RootPart = Player.Character:FindFirstChild("LowerTorso")
	end)
	
end)

Video:

1 Like

Hey there, Thanks for your help but I don’t get how this would help in fixing my moving platforms…

Oh lol i just noticed, yeah tweened/lerped parts wont move unanchored parts with it, here id use an AlignOrientation and AlignPosition instead of lerps

1 Like

Ohh, can you explain a bit more on how I would use AlignOrientation and AlignPosition in my contraption. Sorry, I am beginner in scripting. Thanks

Search the forums for moving platforms. There are already a bunch of posts about this.
A great way to do it is using PrismaticConstraints because they are physics based.
Here’s a tutorial type platform model I made just because there were a lot of people asking your same question.

1 Like

I have this method kind of working

but I can’t figure out why this is glitching the player of the platform…

Any solution to that, mate?

Thanks

It may be the speed that your platform is moving.

Is the platform the anchored Part, or are you using an unanchored Part welded to a tweened anchored Part?

CFraming is horrible for platforms, but using the physics aspect of an unanchored Part the player is standing on welded to a tweened Anchored Part may help.

1 Like

Yea, speed can matter here.
It’s an anchored tweened CFrame part.

I will try out welding an un anchored part with tweened anchored part to see if it solves the problem.

Otherwise, I will check out the platform model you sent earlier and let you know!

Thank you so much for the help

1 Like

Sounds good.
If you decide to use the PrismaticConstraint method to move at a fast speed you may want to tweak the LinearResponsiveness to a lower number so the platform doesn’t instantly accelerate to it’s Velocity and throw the player off.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.