How to fix this?

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)

Ok i found the A.CFrame * Step was wrong, it should be Step * A.CFrame because then Step is a difference between new and old cframe of platform, then it adds to A.CFrame, and A being moved

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.