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)
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)
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