Player falling off moving platform

Hello, I am trying to make a platform that slides back and forth, but the player keeps falling off.
I want to make it so the player stays on while it moves.
Here is the video:


I tried looking through other solutions on the dev form, but they are all too complicated for me.

Here is my code:

local TweenService = game:GetService('TweenService')
local info = TweenInfo.new(4, Enum.EasingStyle.Linear)
local goal_left = {}
goal_left.Position = script.Parent.Position - Vector3.new(0,0,96)
local left_tween = TweenService:Create(script.Parent, info, goal_left)
--The code that waits 5 seconds and then plays the tween is for testing
task.wait(5)
left_tween:Play()
script.Parent.Player1:GetPropertyChangedSignal('Value'):Connect(function() --For the button
	left_tween:Play()

end)

Is anyone able to help me?

4 Likes

Try this tutorial:

3 Likes

It works a little well, but it does not really fit my needs. It’s too fast and I can’t find a way to slow it down, and I can’t find a way to get it not to repeat but still make the tween work properly.
This is the script I got out of the tutorial:

local TweenService = game:GetService('TweenService')
local RunService = game:GetService("RunService")
local part = script.Parent
local TweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, -1, Enum.EasingDirection.InOut, true) --Set as linear as an attempt to slow it down

local tween = TweenService:Create(part, TweenInfo, {
	CFrame = part.CFrame * CFrame.new(0,0,-96)
})
script.Parent.Player1:GetPropertyChangedSignal('Value'):Connect(function()
	tween:Play()
end)

--velocity = deltaPosition / time
local lastPosition = part.Position
RunService.Stepped:Connect(function(_, deltaTime)
	local currentPosition = part.Position
	local deltaPosition = currentPosition - lastPosition
	local velocity = deltaPosition/ deltaTime
	
	part.AssemblyLinearVelocity = velocity
	
	lastPosition = currentPosition
end)
1 Like

The first variable (int) in TweenInfo is the duration of the Tween. You wanted it to be 4 seconds long so you can simply change it (this will make it slower)

local TweenInfo = TweenInfo.new("Duration as an integer, ex: 4 (seconds)", Enum.EasingStyle.Linear, -1, Enum.EasingDirection.InOut, true) --Set as linear as an attempt to slow it down

Whereas your second problem, would you mind elaborating more?

Is there a way to get it to stop and still get it to work without repeating also I’m planning to make it so that when the player gets on the button it goes left, but when the player is off the button, it goes back

Thanks to everyone who tried to help me, especially Probloxed123 for the tutorial, I found the solution and changed my script to the following:

local TweenService = game:GetService('TweenService')
local RunService = game:GetService("RunService")
local part = script.Parent
local originalPosition = part.Position
local TweenInfo = TweenInfo.new(4, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, -1, true)

local tween = TweenService:Create(part, TweenInfo, {
	CFrame = part.CFrame * CFrame.new(0, 0, -96)
})
script.Parent.Player1:GetPropertyChangedSignal('Value'):Connect(function()
	if script.Parent.Player1.Value then
		tween:Play()
	else
		tween:Pause()
	end
end)

local lastPosition = part.Position
RunService.Stepped:Connect(function(_, deltaTime)
	local currentPosition = part.Position
	local deltaPosition = currentPosition - lastPosition
	local velocity = deltaPosition / deltaTime

	part.AssemblyLinearVelocity = velocity

	lastPosition = currentPosition
end)

2 Likes

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