I made a script that stabilizes parts relative to a position. Easy to modify

You can use it for walking upside down too.

Just change some of the values and the references.

local CFramee = script.Parent.CFrame

local BGStabilizer = Instance.new("BodyGyro")
BGStabilizer.CFrame = CFramee

BGStabilizer.MaxTorque = Vector3.new(50000000,0,0)
BGStabilizer.Name = "owiteoiaA"
BGStabilizer.Parent = script.Parent

local deb = false
script.Parent.Parent.Wheel.Touched:Connect(function()
	if deb == false and script.Parent:FindFirstAncestorWhichIsA("Model") and script.Parent:FindFirstAncestorWhichIsA("Model"):FindFirstChild("VehicleSeat")  then
		deb = true
		
		local raycastParams = RaycastParams.new()
	
		raycastParams.IgnoreWater = true

		local DownraycastResult = workspace:Raycast(script.Parent.Position, (script.Parent.CFrame.UpVector*5), raycastParams)
		local DownhitPart, DownhitPosition, Normal
		if DownraycastResult then
			DownhitPart, DownhitPosition, Normal= unpack({DownraycastResult.Instance, DownraycastResult.Position, DownraycastResult.Normal})
		end
		if Normal then
		print(Normal)	
			if Normal.Z > 0 or Normal.X > 0 then
				BGStabilizer.CFrame = script.Parent.CFrame * CFrame.Angles( math.rad((180 * (1 - Normal.Y ))),0,0 )

				
			elseif Normal.Z < 0 or Normal.X < 0 then
				BGStabilizer.CFrame = script.Parent.CFrame * CFrame.Angles( math.rad(-1*(180 * (1 - Normal.Y ))),0,0 )
			else
				BGStabilizer.CFrame = script.Parent.CFrame * CFrame.Angles( math.rad((180 * (1 - Normal.Y ))),0,0 )

			end
		end
		
		wait(2)
		deb = false	 
	end
end)
1 Like