Ragdolled body twitching when Shiftlocked

Whenever I shiftlock, for some reason my whole body just starts twitching. And Im using a slight modded version of the Ragdoll Module made by @ig3v, version: 1.2.1

Wherever my camera goes, the ragdoll follows too, dont know why honestly

function ragdoll:doRagdoll(toggle:boolean):boolean
	local success, err = pcall(function()	
		initCollisionGroup()
		self:debug(initRagdollFolder())
		
		local characterRagdoll = getRagdollModel(self.RagdollType, self.Character)
		self:debug(characterRagdoll)
		
		local characterHumanoid = characterRagdoll:FindFirstChildOfClass("Humanoid")
		self:debug(characterHumanoid)
		
		if characterHumanoid then
			local isRagdolling =
				(self.RagdollType == "DeathBody")
				or (self.RagdollType == "Toggle" and toggle)

			characterHumanoid.PlatformStand = isRagdolling
			characterHumanoid.AutoRotate = not isRagdolling

			if self.RagdollType == "DeathBody" then
				characterHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				characterHumanoid.BreakJointsOnDeath = false
				characterHumanoid.Health = -math.huge
			end
		end

		for _, child in characterRagdoll:GetChildren() do
			if self.CollisionsEnabled then
				if child:IsA("BasePart") then
					local box, weld = createOrGetCollisionBox(child)
					if not self._ragdollCache[child] then
						self._ragdollCache[child] = {}
					end
					
					if self._ragdollCache[child] and not self._ragdollCache[child].OldCollisionGroup then
						self._ragdollCache[child].OldCollisionGroup = child.CollisionGroup
					end
					
					if self.RagdollType == "Toggle" then
						box.CanCollide = toggle
						box.Massless = not toggle
						child.CollisionGroup = (toggle and "__ragdollColl") or self._ragdollCache[child].OldCollisionGroup
					elseif self.RagdollType == "DeathBody" then
						box.CanCollide = true
						box.Massless = false
						child.CollisionGroup = "__ragdollColl"
					end
					
					if self.DebugMode then
						box.Transparency = 0.5
						box.Material = Enum.Material.Plastic
						box.Color = Color3.new(1,0,0)
						
						child.Transparency = 0.5
					end
				end
			end
		end
		
		for _, child in characterRagdoll:GetDescendants() do
			if (child:IsA("LocalScript") or child:IsA("Script") or child:IsA("ForceField")) and self.RagdollType == "DeathBody" then
				child:Destroy()
			end
		end
		
		characterRagdoll.Parent = (self.RagdollType == "DeathBody" and initRagdollFolder()) or characterRagdoll.Parent
		self:debug(characterRagdoll.Parent)
		
		wait()
		
		for _, child in characterRagdoll:GetDescendants() do
			if child:IsA("BasePart") then
				child.CustomPhysicalProperties = ((self.RagdollType == "DeathBody" or (self.RagdollType == "Toggle" and toggle)) 
					and PhysicalProperties.new(self.Density, self.Friction, self.Elasticity))
					or nil

				if self.RagdollType == "DeathBody" then
					child.CanQuery = false
					child.CanTouch = false
				end
				
				if self.Player and RunService:IsServer() then
					if (self.RagdollType == "Toggle" and toggle) or self.RagdollType == "DeathBody" then
						child:SetNetworkOwner(self.Player)
					else
						child:SetNetworkOwnershipAuto()
					end
				end
			end
			
			if child:IsA("Motor6D") then
				if self.RagdollType == "Toggle" and self._ragdollCache[child] then
					self._ragdollCache[child].Motor.Enabled = not toggle
					self._ragdollCache[child].BallSocket.Enabled = toggle

					continue
				end

				local ball = join(child, self.TwistAngleRange)
				
				self:debug(child)
				self:debug(ball)
				
				if self.RagdollType == "DeathBody" then
					child.Enabled = false
					ball.Enabled = true
				else
					if not self._ragdollCache[child] then
						self._ragdollCache[child] = {}
					end

					if ball and child then
						self._ragdollCache[child].Motor = child
						self._ragdollCache[child].BallSocket = ball
					end

					child.Enabled = not toggle
					ball.Enabled = toggle
				end
			end
		end
		
		if self.RagdollType == "DeathBody" then
			local doFade, fadeTime = self.DoFadeOnRemovalReached, self.FadeTime -- after cleanup these are nil
			
			task.delay(self.RemovalTime, function()
				if doFade then
					for _, child in characterRagdoll:GetDescendants() do
						if child:IsA("BasePart") or child:IsA("Decal") or child:IsA("Texture") then
							TweenService:Create(child, TweenInfo.new(fadeTime, Enum.EasingStyle.Linear), {
								Transparency = 1
							}):Play()
						end
					end
					
					game.Debris:AddItem(characterRagdoll, fadeTime)
				else
					game.Debris:AddItem(characterRagdoll, 0)
				end
			end)
			
			wait()
			
			characterRagdoll.PrimaryPart.AssemblyLinearVelocity = self.Character.PrimaryPart.AssemblyLinearVelocity
			characterRagdoll.PrimaryPart.AssemblyAngularVelocity = self.Character.PrimaryPart.AssemblyAngularVelocity
			
			self:debug(characterRagdoll.PrimaryPart.AssemblyLinearVelocity)
			self:debug(characterRagdoll.PrimaryPart.AssemblyAngularVelocity)

			local tag = Instance.new("ObjectValue")
			tag.Value = characterHumanoid
			tag.Name = "_ragdoll"

			tag.Parent = self.Character

			game.Debris:AddItem(tag, 3)
		end
	end)
	
	if success then
		self._ragdolling = (self.RagdollType == "DeathBody" and true) or self.RagdollType == "Toggle" and toggle
	end
	
	if self.RagdollType == "DeathBody" then
		for i,v in self.Character:GetDescendants() do
			if v:IsA("BasePart") or v:IsA("Texture") or v:IsA("Decal") then
				v.Transparency = 1
			end

			if v:IsA("BasePart") then
				v.CanCollide = false
				v.CanTouch = false
				v.CanQuery = false
				v.Anchored = true
			end

			if v:IsA("ForceField") then
				v:Destroy()
			end
		end
	end
	
	self:debug(success)
	self:debug(err)
	
	if self.AutoDestroy and self.RagdollType == "DeathBody" then
		self:destroy()
	end
	
	return success, err
end

when you shift lock your character always rotates to camera direction causing movement

use physics service to make all limbs non collidable to each other to fix this issue

1 Like

Half of the solution, i just have to added uhm joint limits, and rotation stuff, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.