How to make a moving part that moves the player when he stands on it?

I’ve been searching for tutorials on YouTube on how to do so, but with no hope. Can you guys please tell me how to make a moving part that moves the player when he stands on it?

Thanks for anyone that will help me!

3 Likes

This uses a CFrame approach that basically offsets the player’s CFrame by the same amount that the moving part moved

4 Likes
local MovingPart = game.Workspace:WaitForChild("MovingPart") -- Change this to the path to the part you want to move

local debounce = false

function onTouched()
	if debounce == false then
		debounce = true
		
	for i = 1, 10 do
		MovingPart.CFrame = MovingPart.CFrame * CFrame.new(0, 1, 0) -- Adjust to your liking
			task.wait()
		end
		debounce = false
	end
end

MovingPart.Touched:Connect(onTouched)

Hope this helps!

2 Likes

you can use align position and align orientation in the part to move it (can even do this client side) and it should also move the player if they are standing on the part when it moves

1 Like

I’ll test it and see.

Edit: Nope, it doesn’t work. It implements the opposite. Whenever I touch it, its Y axis value increases by 1. It doesn’t work

You marked my post as the solution, so I guess it ended up working? I mean, if the Z axis is off, just play around with the numbers and it should change and do what you want.

No, that’s not what I want, mate. As you know, when you make a moving part and stand on it, it doesn’t move you to the direction that the part is going to. You have to make some codes to make the player move in the direction that the part is moving to when he stands on it.

You could use TweenService. Have you learned about that yet?

Yea, I have a basic understanding of it, but will it make the player move when he stands on the moving part?

It should. You can try it and let me know if it doesn’t work or errors in any way.

1 Like

Alright, I’m gonna use it and see if it works. I’ll edit this message to say if it works or not

Edit: No it doesn’t work lol. When I stand on the part, the player doesn’t move with it.

Hey, did you ever find a soulution to this? I’m trying to figure it out too currently.

Unfortunately no. I haven’t figured out any solution to it.

Pm me I can help tommorow but I’m going to bed right now

I gotchu. Time to fix this problem. First put a server script inside the moving part.

local part = script.Parent
local TS = game:GetService('TweenService')
local TI = TweenInfo.new(5, Enum.EasingStyle.Linear,Enum.EasingDirection.InOut, -1, true)

local tween = TS:Create(part, TI, {Position = part. Position + Vector3.new(10,0,0) --[[Change this to your liking]]--)
tween: Play()

What the server script does is just make a tween that repeats forever.
Now, Put this local script inside StarterCharacterScripts

local char = game.Players.LocalPlayer.Character
local part = workspace.MovingPart -- Change this accordingly
local RS = game:GetService('RunService')
local connection
local lastcframe
connection = RS.Heartbeat:Connect(function()
   local rp = RaycastParams.new() -- Params to ignore the character
   rp.FilterDescendantsInstances = {char}
   rp.FilterType = Enum.RaycastFilterType.Exclude
   local ray = workspace:Raycast(char.HumanoidRootPart.Position, Vector3.new(0,-100,0), rp) --[[We
   need to raycast to see if the player is standing on the platform, so we can move him]]--
   if ray and ray. Instance == part then
      local currentcframe = ray.Instance.CFrame -- Store the current cframe in a variable
      if lastcframe then
         local relativecframe = currentcframe * lastcframe:Inverse() --[[ What
         this does is just get the next position to move the character to. lastcframe
         would always be a bit backwards so we're inversing it to get it as if it was in front of the
         currentcframe]]--
         rel *= char.HumanoidRootPart.CFrame -- Move the character along with the platform (rel needs to be multipled first)
      end
      lastcframe = currentcframe -- Setting a cframe in front so it wont be a constant
   else
      lastcframe = nil -- Setting it to nil so we can start anew since the player jumped off the platform
   end
end)
char.Humanoid.Died:Connect(function()
   connection: Disconnect() --[[Disconnect the runservice connection so
   our body parts stop moving]]--
end)

With this, you should be able to make a moving platform that moves the player as well

Haven’t tested it yet, but I marked it as the solution as I’m sure it’ll work.

Thank you for your help!

Funny isn’t it, its been a whole year.
PS: One change I didn’t make earlier, it should be heartbeat, not renderstepped

2 Likes

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