Here is the demo game I have been working on: train! - Roblox
I am using TweenService to tween the parts of the train, but the player just slides off the train. How can I make a player move with the train, similarly to JailBreak?
One of the ways you can do this is when the tween plays then you could get the players character and anchor the characters rootpart to the train. That is probably the easiest way.
Yes. I believe that it is not working because there are multiple train carriages and they all have the same name. I am currently experimenting with fixing this…
IN THE FILE YOU GAVE ME, THE TRACKS WHERE ABOUT THE SAME SIZE AS THE TRAIN.
THIS MADE THE SCRIPT DETECT THE PLAYER AS BEING ON TOP THE TRACK INSTEAD OF THE TRAIN PART.
I MADE THE TRACKS SHORTER TO MAKE THIS NOT HAPPEN.
IT WORKS FINE NOW.
please let me know if you need any more help with the script / want to understand it better.
This script works if there are multiple parts that has the same name for me:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local LastTrainCFrame
local Function
local Function2
Function = RunService.Heartbeat:Connect(function()
--------------------------------------------------------------- CHECK PLATFORM BELOW
local character = player.Character or player.CharacterAdded:Wait()
local RootPart = character.Torso
local Whitelist = {} -- Table of Every "RaftTop" (You could just make a model or folder for it.)
local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))
local Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,Whitelist)
if Hit and Hit.Name == "RaftTop" then -- Change "RaftTop" to whatever the moving part's name is
--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION
local Train = Hit
if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
LastTrainCFrame = Train.CFrame -- This is updated later.
end
local TrainCF = Train.CFrame
local Rel = TrainCF * LastTrainCFrame:inverse()
LastTrainCFrame = Train.CFrame -- Updated here.
RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
--print("set")
else
LastTrainCFrame = nil -- Clear the value when the player gets off.
end
Function2 = player.Character.Humanoid.Died:Connect(function()
Function:Disconnect() -- Stop memory leaks
Function2:Disconnect() -- Stop memory leaks
end)
end)