Moving platform for players using TweenService?

Hello there. I was wondering about how to make a moving platform for a player using TweenService. I tried searching for a similar post, but could not find one, so I decided to make one myself. When you use TweenService to move a platform, the platform does move, but the player does not move with the platform (you have to move the player manually).

I went to the ToolBox to see what other ways people use to make the platform move, and I found one that the player moves with the platform.

I saw inside the platform and the script, and I found out that the platform uses BodyGyro and BodyPosition to make it move.

The code that I used to make my platform move is:

-- Variables --

local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")

local Folder = script.Parent
local Platform = Folder:WaitForChild("Platform")
local Start = Folder:WaitForChild("Start")
local End = Folder:WaitForChild("End")

-- Tables --

local TweenInformation = TweenInfo.new(
	5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0	
)

-- Scripting --

while true do
	local Tween = TweenService:Create(Platform, TweenInformation, {Position = End.Position})
	Tween:Play()
	wait(7)
	local Tween2 = TweenService:Create(Platform, TweenInformation, {Position = Start.Position})
	Tween2:Play()	
	wait(7)
end

Is there a way that you could make a platform that moves a player from one location to another using TweenServices?

9 Likes

This can be done by using proxies. You can tween a BodyGyro and BodyPosition’s properties to achieve the same effect as tweening the part’s CFrame itself, the responsibility of moving the platform is just handed over to the physics engine, which makes sure to move the player.

By the way, your while true loop could be replaced by modifying the TweenInfo a little:

TweenInformation = TweenInfo.new(
    5, -- time
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    -1, -- repeat count, -1 = inf
    true, -- reverses
    2 -- delay
)

I don’t know if the last parameter actually delays every time it moves, so you might need to keep your setup.

One last note: You might want to set the part’s network ownership to the server just so the changes to BodyPosition/BodyGyro does not look terrible…

5 Likes

Thank you for your reply. I have read both of those articles, but they do not solve my problem. My question is not how to tween a model, but how would I tween a part and make a player move with the part, while being able to move on the part as well (shown in the second GIF). I do appreciate that you took your time to find the articles and I thank you. I did search for this certain scenario, but could not find any posts.

4 Likes

Thank you for your reply. How would I Tween an object’s BodyGyro or/and BodyPosition?

1 Like

basically:

TweenService:Create(
	BodyGyro,
	--[[TweenInfo]],
	{CFrame = --[[CFrame Value]]}
)

and similarly:

TweenService:Create(
	BodyPosition,
	--[[TweenInfo]],
	{Position = --[[Vector3 Value]]}
)

TweenService can tween any property as long as it conforms to a certain range of types, as said by its page on the dev wiki.

23 Likes

It works perfectly. The only things needed are adjustments in the BodyPosition’s properties, but other than that, it works perfect, and as it should. Thank you for helping me and answering my problem. Have a wonderful night.

3 Likes

I have same problem
I need that platform and I made BodyPosition and BodyGyro tween but it works only when not anchored so I can’t really make floating moving platforms
(also this exact model from toolbox on second gif don’t work)
if somebody is interested in code:

local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(
	script.Parent.BodyPosition,
	TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
	{
		Position = script.Parent.Parent.End.Position
	}
)
local tween1 = TweenService:Create(
	script.Parent.BodyPosition,
	TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
	{
		Position = script.Parent.Parent.Start.Position
	}
)
local tween2 = TweenService:Create(
	script.Parent.BodyGyro,
	TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
	{
		CFrame = script.Parent.Parent.Start.CFrame
	}
)
local tween3 = TweenService:Create(
	script.Parent.BodyGyro,
	TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
	{
		CFrame = script.Parent.Parent.Start.CFrame
	}
)
while true do
	tween:Play()
	tween2:Play()
	wait(5)
	tween1:Play()
	tween3:Play()
	wait(5)
end

I’m Waiting for help because I try it more than two hours now

Edit. I Made it without tweens, using BodyPosition so nvm

1 Like