I am currently developing an Anti-Derailer script that will be similar to the RailConstraint in Roblox, but less complicated. The script aims to allow a train or part to move through the rail without any offset. However, I have encountered an issue that needs to be addressed.
The current script only works when the rail is straight and facing forward on the Z-axis. If I make the part move through the rail without offsetting the X-axis, it will go through. Unfortunately, this method doesn’t work with a rotated rail, even if the train or part is at the same angle as the rail.
Since my knowledge of scripting, especially with CFrame and Math, is limited, I have been trying various methods to solve this issue.
local part = script.Parent
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local function onTouch(otherPart)
if otherPart.Name == "Point" then
game:GetService('TweenService'):Create(part, TweenInfo, {["CFrame"] = otherPart.CFrame * CFrame.new(0, 0, -1) + part.AssemblyLinearVelocity.Unit}):Play()
end
end
part.Touched:Connect(onTouch)
I even used ChatGPT to solve the problem, but that didn’t work either.