Hello,
I recently made a train system using Align Position/Orientation. What is supposed to happen is when a player walks on the train they move with the train. The script is a local script placed in StarterPlayerScripts. My old train ran on tweening the CFrame of the primary part of the train. The script worked perfectly there, but now since I switched to align position, the player gets shot down the train like it is a conveyor! I want the players to be able to walk on the train like how it used to work when it was ran with CFrame.
I hope you can help, thanks.
Player on train script
--//Variables\\--
wait(1+math.random())
local TrainFolder = game.Workspace.Train
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local LastCF
local LastPart
RSFunction = RunService.Heartbeat:Connect(function()
local Root = Player.Character.HumanoidRootPart
local ray = Ray.new(Root.CFrame.p, Vector3.new(0,-20,0))
local hit = game.Workspace:FindPartOnRayWithIgnoreList(ray, Player.Character:GetChildren())
if (hit and hit:IsDescendantOf(TrainFolder)) then
if hit ~= LastPart then
LastCF = nil
end
local Train = hit
if not LastCF then
LastCF = Train.CFrame
end
local TrainCF = Train.CFrame
local Rel = TrainCF * LastCF:Inverse()
LastCF = Train.CFrame
Root.CFrame = Rel * Root.CFrame
LastPart = Train
else
LastCF = nil
end
end)
for i,v in pairs(game.Workspace.TrainStop:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and LastCF ~= nil then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-104.85, 2.9, 152.4)
end
end)
end
DiedFunction = Player.Character.Humanoid.Died:Connect(function()
RSFunction:Disconnect()
DiedFunction:Disconnect()
end)
Your code works I believe, however AlignPosition and AlignOrientation already have a built system to keep the player on the moving platform anyways, so your code is completely unnecessary. I tried this before on a ship, and sadly it had the same result. Somehow the humanoid’s default behavior of sticking on the platform and the raycasting code combines to make the character slide.
I think the issue is the player is stepping on things that are welded to the part with align position and orientation, causing the system not to make the player move along
It works with welds, I know for a fact. One thing I noticed is that the replication behavior of this is extremely weird. Are you setting the attachment positions on the Client or the Server, and who is the network owner?
Network Owner only works on parts that arn’t welded or anchored, and I am setting the attachment positions on the server. How my system works is that the attachments of the align position are never changed, the attachment1 of the align position is a part that gets tweened with CFrame
If you’re using align orientation and align position, then the parts are unanchored. It works on welded parts that are welded to an unanchored object. You must be changing the attachments, since thats the only way the train can move? I am confused.
That was my old system, it was overall very buggy and choppy. I wanted to be able to control the CFrame as well as benefits of the physics simulation all at once
Seeing your gif, it seems like you want a wild west inspired system. I believe that game has the train anchored completely and instead uses a custom method of calculating the train’s CFrame. Since it follows a set track, I cant imagine this being too difficult. You can do an equation like speed = speed + acceleration * dt and position = position + speed * dt.