How to fix this script?

  1. What do you want to achieve? Fix my mobile shiftlock script.

  2. What is the issue? My game has ragdoll, but the mobile shiftlock is making the character unable to ragdoll correctly.

The video below shows the ragdoll.
robloxapp-20230121-1224314.wmv (1.3 MB)

  1. What solutions have you tried so far? I tried to enable and disable the humanoid’s AutoRotate but nothing different happended.

Mobile shiftlock script:

local MobileCameraFramework = {}
local players = game:GetService("Players")
local runservice = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character.Humanoid
local camera = workspace.CurrentCamera
local button = script.Parent
local val = script.Autorot
--Visiblity
uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.ButtonX then
		script.Parent.Visible = true
		
		end
	end)

if uis.TouchEnabled == true then
	script.Parent.Visible = true
end



local states = {
	OFF = "rbxasset://textures/ui/mouseLock_off@2x.png",
	ON = "rbxasset://textures/ui/mouseLock_on@2x.png"
}
local MAX_LENGTH = 900000
local active = false
local ENABLED_OFFSET = CFrame.new(1.7, 0, 0)
local DISABLED_OFFSET = CFrame.new(-1.7, 0, 0)
local function UpdateImage(STATE)
	button.Image = states[STATE]
end

local function GetUpdatedCameraCFrame(ROOT, CAMERA)
	return CFrame.new(root.Position, Vector3.new(CAMERA.CFrame.LookVector.X * MAX_LENGTH, root.Position.Y, CAMERA.CFrame.LookVector.Z * MAX_LENGTH))
end
local function EnableShiftlock()
	humanoid.AutoRotate = val.Value
	UpdateImage("ON")
	root.CFrame = GetUpdatedCameraCFrame(root, camera)
	camera.CFrame = camera.CFrame * ENABLED_OFFSET
end
local function DisableShiftlock()
	humanoid.AutoRotate = val.Value
	UpdateImage("OFF")
	camera.CFrame = camera.CFrame * DISABLED_OFFSET
	pcall(function()
		active:Disconnect()
		active = nil
	end)
end
UpdateImage("OFF")
active = false
function ShiftLock()
	if not active then
		active = runservice.RenderStepped:Connect(function()
			EnableShiftlock()
		end)
	else
		DisableShiftlock()
	end
end
local ShiftLockButton = CAS:BindAction("ShiftLOCK", ShiftLock, false, "On")
CAS:SetPosition("ShiftLOCK", UDim2.new(0.8, 0, 0.8, 0))
button.MouseButton1Click:Connect(function()
	if not active then
		active = runservice.RenderStepped:Connect(function()
			EnableShiftlock()
		end)
	else
		DisableShiftlock()
	end
end)




return MobileCameraFramework

Ragdoll script:

local Char = script.Parent
local pla = game.Players:GetPlayerFromCharacter(Char)
local PhysicsService = game:GetService("PhysicsService")

Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
local shift = game.Players:GetPlayerFromCharacter(Char)

for _, v in pairs(Char:GetDescendants()) do
	local player = game.Players:GetPlayerFromCharacter(Char)
	if v:IsA("Motor6D") then
		local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
		Att0.CFrame = v.C0
		Att1.CFrame = v.C1
		Att0.Parent = v.Part0
		Att1.Parent = v.Part1
		local BSC = Instance.new("BallSocketConstraint")
		BSC.Attachment0 = Att0
		BSC.Attachment1 = Att1
		BSC.Parent = v.Part0
		
		pla.PlayerGui.ShiftLockButton.ImageButton.ShiftGUI.Autorot.Value = false
		BSC.LimitsEnabled = true
		BSC.TwistLimitsEnabled = true
		Char.Humanoid.RequiresNeck = false
		
		
		Char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		for _, v in ipairs(Char:GetChildren()) do
			if v:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(v, "Ragdoll")
			end
		end
		Char.HumanoidRootPart:ApplyAngularImpulse(Vector3.new(-90, 0, 0))
		v.Enabled = false
	end
end

Char.HumanoidRootPart.CanCollide = false

wait(1.5)
Char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
for _, v in pairs(Char:GetDescendants()) do
	if v:IsA("Motor6D") then
		v.Enabled = true
	end
	end
	for _, v in ipairs(Char:GetChildren()) do
		if v:IsA("BasePart") then
			PhysicsService:SetPartCollisionGroup(v, "Default")
		end
end

for _, v in ipairs(Char:GetDescendants()) do
	if v:IsA("BallSocketConstraint") then
	v:Destroy()
	end
end
for _, v in ipairs(Char:GetDescendants()) do
	if v:IsA("Attachment") and v.Name == "Attachment" then
		v:Destroy()
	end
end
pla.PlayerGui.ShiftLockButton.ImageButton.ShiftGUI.Autorot.Value = true
wait(0.1)
script:Destroy()

How would i make the ragdoll works correctly with the mobile shiftlock?

1 Like

Simple just put a boolean value so it turns false when the player is ragdolled and put it in the shift lock loop or runservice function so they update at everyframe