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.

https://gyazo.com/07834920ac940a95385843e60c9bef64
script:

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
------------------------------------------------------------------
tool.Equipped:Connect(function(mouse)
	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
			print("Loop")
			local pos = (mouse.Hit.Position)
			if value.Value == one then
				one.CFrame = CFrame.new(pos + Vector3.new(0,6,0))
			end
		end
	end)
end)

tool.Unequipped:Connect(function(mouse)
	gui.Parent = plr:WaitForChild("BackPack"):WaitForChild("DeployableLadder")
	print("Weapon unequipped")
	equipped = false
	one.Transparency = 1
end)

useri.InputBegan:Connect(function(input)
	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)
			else
				print("Value nil")
			end
		end
	end
end)

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

one.CFrame = CFrame.new(pos + Vector3.new(0,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:
https://gyazo.com/8e98e64a34c7cd84c9a1e3410d739626

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: https://developer.roblox.com/en-us/api-reference/property/Mouse/hit

if mouse.Target then
     local pos = (mouse.Hit.Position)
     if value.Value == one then
         one.CFrame = CFrame.new(pos + Vector3.new(0,6,0))
    end	
end
1 Like
one.CFrame = CFrame.new(pos + Vector3.new(0,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

30charsssssssssss

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