What do you want to achieve?
Being able to jump around while a ship is on the move.
What is the issue?
Jumping while on a moving ship seems to work fine, but when the player stays still, they start to slide towards the front.
Here’s the script:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local LastHit
local LastTrainCFrame
local Function
local Function2
local Whitelist = {workspace.Orion["Cruiser Kappa"]}
Function = RunService.Heartbeat:Connect(function()
local RootPart = player.Character.HumanoidRootPart
local Ignore = player.Character
local ray = Ray.new(RootPart.CFrame.p, Vector3.new(0,-50,0))
local Hit, Position, Normal, Material
if LastHit then
Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,{LastHit})
if not Hit then
Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,Whitelist)
end
else
Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,Whitelist)
end
if Hit then
local Train = Hit
if not LastTrainCFrame then
LastTrainCFrame = Train.CFrame
end
local TrainCF
if Train ~= LastHit and LastHit then
TrainCF = LastHit.CFrame
else
TrainCF = Train.CFrame
end
local Rel = TrainCF * LastTrainCFrame:inverse()
LastTrainCFrame = Train.CFrame
RootPart.CFrame = Rel * RootPart.CFrame
LastHit = Train
if Train ~= LastHit then
LastTrainCFrame = Train.CFrame
end
else
LastTrainCFrame = nil
end
if not Function2 then
Function2 = player.Character.Humanoid.Died:Connect(function()
Function:Disconnect()
Function2:Disconnect()
end)
end
end)
How can I fix this? The ship uses bodymovers FYI.