Tool keeps randomly dissapearing?

I’m trying to make “inverse kinematics” but for R6, but for some reason the tool keeps randomly dissapearing whenever I equip it.

By randomly dissapearing, I mean that it just deletes itself from the inventory. I feel like it might have to do something with this block of code but I’m not sure:

		if rightArm:FindFirstChild('RightGrip') then
			rightArm.RightGrip.Part0 = torso
			rightArm.RightGrip.C0 = CFrame.new(1.5, 0, -2)
		end
Code
-- StarterPlayer/StarterPlayerScripts/LocalScript

local Storage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')

local player = game.Players.LocalPlayer

local IKModule = require(Storage.R6IK)

player.CharacterAdded:Connect(function(character)
	local t:{ BasePart } = {
		character:WaitForChild('Left Arm'), character:WaitForChild('Right Arm'),
		character:WaitForChild('Left Leg'), character:WaitForChild('Right Leg')
	}
	
	for i, v in t do
		v:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
			v.LocalTransparencyModifier = 0
		end)
	end
end)

RunService.Stepped:Connect(function()
	local character = player.Character
	local torso = character and character:FindFirstChild('Torso')
	local rightArm = character and character:FindFirstChild('Right Arm')
	
	if character and torso and rightArm then
		local tool = character:FindFirstChildWhichIsA('Tool')
		
		if rightArm:FindFirstChild('RightGrip') then
			rightArm.RightGrip.Part0 = torso
			rightArm.RightGrip.C0 = CFrame.new(1.5, 0, -2)
		end

		local leftShoulder:Motor6D = torso:FindFirstChild('Left Shoulder')
		local rightShoulder:Motor6D = torso:FindFirstChild('Right Shoulder')
		if not leftShoulder or not rightShoulder then return end

		IKModule.setOriginalC0(leftShoulder)
		IKModule.setOriginalC0(rightShoulder)
		
		if not tool or not tool:FindFirstChild('LeftHandle') or not tool:FindFirstChild('RightHandle') then
			IKModule.ResetIK(leftShoulder)
			IKModule.ResetIK(rightShoulder)
			
			return
		end
		
		IKModule.UpdateIK(leftShoulder, Vector3.new(0, 0.5, 0), tool.LeftHandle.Position, 0.3, 0.5)
		IKModule.UpdateIK(rightShoulder, Vector3.new(0, 0.5, 0), tool.RightHandle.Position, 0.3, 0.5)
	end
end)


-- ReplicatedStorage/R6IK

local module = {  }

function module.setOriginalC0(motor:Motor6D)
	if motor:GetAttribute('originalC0') == nil then motor:SetAttribute('originalC0', motor.C0) end
end

function module.UpdateIK(motor:Motor6D, offset:Vector3, goal:Vector3, weight:number, smoothing:number)
	local angleOffset = CFrame.fromOrientation(math.pi / 2, 0, 0)

	local worldSpace = motor.Part0.CFrame:ToWorldSpace(CFrame.new(offset) * motor:GetAttribute('originalC0'))
	local lookAt = CFrame.lookAt(worldSpace.Position:Lerp(goal, math.clamp(weight, 0, 1)), goal) * angleOffset
	local objectSpace = motor.Part0.CFrame:ToObjectSpace(lookAt)

	motor.Transform = CFrame.new(0, 0, 0)
	motor.C0 = motor.C0:Lerp(objectSpace, smoothing)
end

function module.ResetIK(motor:Motor6D)
	motor.C0 = motor:GetAttribute('originalC0')
end

return module

Here’s a video showing what’s happening:

Anyone know how to fix this? Thanks.

Don’t know what happened, it wasn’t disappearing anymore for some reason.

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