Hi, i’m making a script where player (i used part to showcase) stands on moving part moved by CFrame like ship or train ect.
Script works when the platforms move linear, but if it rotates a bit, script breaks
here is a example:
Script:
local RunService = game:GetService("RunService")
local A = script.Parent
local LastCFrame = nil
RunService.Heartbeat:Connect(function()
local result = workspace:Raycast(A.Position,Vector3.new(0,-50,0))
if result then
local Hit:Part = result.Instance
if Hit and Hit.Name == "Moveing" then
if not LastCFrame then
LastCFrame = Hit.CFrame
end
local CurrentCFrame = Hit.CFrame
if CurrentCFrame ~= LastCFrame then
local Step:CFrame = CurrentCFrame*LastCFrame:inverse()
A.CFrame = A.CFrame * Step
LastCFrame = CurrentCFrame
end
end
end
end)