Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a character move with a moving platform?

Right before I was about to post a question on why this script wasn't working, I changed an addition to subtraction and viola!

Anyways as the question name suggests, how or what do I have to put into this code to make the character move along with the block.

Does it involve CFraming the player along with their position?

local Part = script.Parent -- this is the Part we will move
local start = script.Parent.Start.Value
local finish = script.Parent.Finish.Value
local Time = 5 -- the time that the script will take to move the part
local Increment = 0.1 -- the Part will move 0.1 studs each time it moves
local Debounce = false
 
local Diff = finish - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, finish).lookVector
 
--local Diff2 = start - Part.Position --All of this became useless once I fixed my code
--local Mag2 = Diff2.magnitude --I'll keep it for reference
--local Dir2 = CFrame.new(Part.Position, start).lookVector -- and to shame myself eternally
function MovePart() -- function to move the Part
	if Debounce then return end -- end the function if debounce is true
	Debounce = true -- make Debounce true so the function can't run
	for n = 0, Mag, Increment do
		Part.CFrame = Part.CFrame + (Direction * Increment)
		wait( (Time/Mag) * Increment )
	end
	wait(3)
	for n = 0, Mag, Increment do
		Part.CFrame = Part.CFrame - (Direction * Increment) --Used to be a plus *Derp*
		wait( (Time/Mag) * Increment )
	end
	Debounce = false
end
 
workspace.Button.ClickDetector.MouseClick:connect(MovePart)

The ClickDetector is there for debugging and the likes, which will be replaced with a loop.

https://gyazo.com/89243d997d2c5d0a97ecf9c8aba3b9d7 (Gif showing heiarchy and the previously broken segment Ignore disappearing issue)

Thank you for any help!

~MBacon15

1 answer

✓ Accepted answer

I worked with this before. So the best thing you can do is to Use BodyMoverObjects. This is because you want the Player to move with the brick, but since you're using CFrame to move the brick, the physics of the brick's movement doesn't exist. So what this does, it Ignores Friction, friction is what grips the player onto the brick . I really suggest to Use BodyPosition , because it uses existing physics. I know this might sound funny, but this is how it realistic it gets. I hope I helped!

4 comments

0

Any idea on where to start with that? If I remember correctly, anchored blocks and bodymovers aren't exactly the best of friends. I wouldn't want the platform drooping under the weight of the player

0

Just Increase the BodyPosition's MaxForce. This is what handles the weight of anything if the MaxForce is high enough.

0

Also, I forgot to mention to add in BodyGyro. BodyGyro keeps the part from rotating since it's floating. I would Increase the MaxTorque on this one too.

0

Thanks! Sorry it took so long to accept, I was in Studio discovering. The tip about the MaxForce helped a ton.

This discussion is preserved as it was. New answers, comments, and votes are closed.