Improving a deployable ladder

Hello everyone, so I have a deployable ladder script. The problem is that I cannot rotate it while moving it because the CFrame is getting set to the same as the mouse all the time. I wanted to ask if there is any way of letting it rotate while moving it.

local tool = script.Parent
local previews = workspace.LadderStuff.Previews
local realadders = workspace.LadderStuff.Stages
local one = previews.PStage1
local two = previews.PStage2
local three = previews.PStage3
local four = previews.PStage4
local five = previews.PStage5
local six = previews.PStage6
local seven = previews.PStage7
local eight = previews.PStage8
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local equipped
local value = script.Parent.CurrentPreview
local useri = game:GetService("UserInputService")
local connection
local gui = script.Parent.LadderGui or plr.PlayerGui.LadderGui
local b1 = realadders.Stage1
local b2 = realadders.Stage2
local b3 = realadders.Stage3
local b4 = realadders.Stage4
local b5 = realadders.Stage5
local b6 = realadders.Stage6
local b7 = realadders.Stage7
local b8 = realadders.Stage8
	gui.Parent = plr.PlayerGui
	print("Weapon equipped")
	one.Transparency = 0.7
	value.Value = one
	equipped = true
	connection = useri.InputChanged:Connect(function(Input, gameProcessed)
		if Input.UserInputType == Enum.UserInputType.MouseMovement then
			if gameProcessed then return end
			if equipped == false then connection:Disconnect() return end
			local pos = (mouse.Hit.Position)
			if value.Value == one then
				one.CFrame = +,6,0))

	gui.Parent = plr:WaitForChild("BackPack"):WaitForChild("DeployableLadder")
	print("Weapon unequipped")
	equipped = false
	one.Transparency = 1

	print("Input made")
	if input.KeyCode == Enum.KeyCode.R then
		print("Correct input")
		if value.Value ~= nil then
			local pre = value.Value
			if pre ~= nil then
				print("Part rotated")
				pre.CFrame = pre.CFrame * CFrame.Angles(0, math.rad(20), 0)
				print("Value nil")

Whenever your setting the new CFrame your not taking into account the current orientation so to fix it do this:

one.CFrame = +,6,0)) * CFrame.Angles(0, math.rad(one.Orientation.Y), 0)
1 Like

One question, do you know why this happens?

The ladder goes to the camera for some reason:

I believe this has to do with the way that Mouse.Hit is calculated so basically a ray is casted and if no Hit is found then it will just make it be 1000 studs away from the camera to fix this check if the Mouse.Target is not nil before updating the position. More info here:

if mouse.Target then
     local pos = (mouse.Hit.Position)
     if value.Value == one then
         one.CFrame = +,6,0))
1 Like
one.CFrame = +,6,0)) * pre.Value

Into the first like make already existing “pre” so like

local pre = CFrame.Angles(0,0,0)
1 Like

It still happens


You need to add one to the mouse’s target filter in the Equipped event. What is happening is when the mouse hovers over the ladder model then it points to that position instead.

mouse.TargetFilter = one

Inside the Equipped event but before the UserInput logic.

1 Like