Trouble with Equip, and unequip welding sword

So i’m currently working on pressing e to equip and unequip the sword and I’m not using a tool, I’m welding the sword to the arm and to the side. What I use to check if the sword is equipped is a bool value that check true or false. So sometimes when I press E, the bool value is true and the sword pulls out, but sometimes it doesn’t. It’s just very incosistent. How can I fix it?

function setup(Character)
	
	
	local handle = ReplicatedStorage.CombatFolder.Sword.Fx.Handle:Clone()
	local SwordCaseWeldPart= ReplicatedStorage.SwordWeldPart:Clone() -- Cloning the sword Case

	
	SwordCaseWeldPart.Parent = Character.HumanoidRootPart
	
	local weld = Instance.new("Weld", Character)
	weld.Part0  = Character.HumanoidRootPart -- Primary Weld is to the humanoidRootPart
	weld.Part1 = SwordCaseWeldPart -- Second is The case
	SwordCaseWeldPart.Anchored =  false
	SwordCaseWeldPart.CFrame = Character.HumanoidRootPart.CFrame -- Putting the sword's models' CFrame to the humanoidRootPart
	
	--- Welding the Sword to the Case

	
	handle.Parent =  SwordCaseWeldPart.Case -- Make sure the sword's parent is the case and not the humanoidRootPart


	local Weld2 = Instance.new("WeldConstraint") --Second Weld Constraint
	Weld2.Name = "SideWeld"
	Weld2.Part0 = handle -- First weld should be the sword
	Weld2.Part1 = SwordCaseWeldPart.Case --Second weld should be the SwordCase
	handle:PivotTo(SwordCaseWeldPart.Case.CFrame * CFrame.new(0,-.2, 2.8)) -- Make sure the Sword Is Pivoted or postion to the SwordCase's CFrame. Tweek it if needed.
	Weld2.Parent = handle -- The parent of the second weld should be the Sword.Primary Part or Handle
	

	
	Character.Equipped.Changed:Connect(function()
		if Character.Equipped.Value == true then
			print("Equipped")
			
			local SideWeld = handle:FindFirstChild("SideWeld")
			
			if SideWeld then
				SideWeld:Destroy()
				warn("SideWeld Destroyed")
				
				
				
			local Motor6d = Instance.new("Motor6D")
			Motor6d.Part0 = Character["Right Arm"]
			Motor6d.Part1 = handle
			Motor6d.Name = "RightArmMotor"
			Motor6d.C1 = CFrame.new(0, 1, 0 ) -- Changes the position/Offset of the sword on the Arm
			Motor6d.Parent = Character["Right Arm"]
			
				
		
			
		else
			print("Unequipped")
			
			local RightArmMotor = Character["Right Arm"]:FindFirstChild("RightArmMotor")
			
			if RightArmMotor then 
				RightArmMotor:Destroy()
				
				handle:PivotTo(SwordCaseWeldPart.Case.CFrame * CFrame.new(0,-.2, 2.8))
				
				handle.Parent = SwordCaseWeldPart.Case
				
				local Weld = Instance.new("WeldConstraint")
				Weld.Name = "SideWeld"
				Weld.Part0 = handle
				Weld.Part1 = SwordCaseWeldPart.Case
				Weld.Parent = handle
				
			end
			
			end
		end
	end)
	
end


for i, v in pairs(game.Players:GetChildren()) do
	repeat task.wait() until v.Character
	v.Character:WaitForChild("Equipped")
	
	setup(v.Character)
	
	v.CharacterAdded:Connect(function(Char)
		Char:WaitForChild("Equipped")
		setup(Char)
		
	end)
end

game.Players.PlayerAdded:Connect(function(Player)

	Player.CharacterAdded:Connect(function(char)

		char:WaitForChild("Equipped")
		setup(char)
		
		
	
	end)
end)
lua
elseif data.action == "equip" then
		if data.Character:FindFirstChild("Equipped") then
			if data.Character.Equipped.Value == false then
				data.Character.Equipped.Value = true
				
			else -- Otherwise/ If it's the opposite and the sword was already equipped
				data.Character.Equipped.Value = false
			end
		else -- adding a boolvalue if there wasn't in the first place.
			
			local Equipped = Instance.new("BoolValue")
			Equipped.Value = true
			Equipped.Name = "Equipped"
			Equipped.Parent = data.Character
			
		end
		
	elseif data.action == "setup" then
		local Equipped = Instance.new("BoolValue")
		Equipped.Value = false
		Equipped.Name = "Equipped"
		Equipped.Parent = data.Character
	end
end)

Does the data.action get updated correctly?

I think the problem might be before it

Yeah It should be getting updated correctly, I can send the local script

Maybe theres a better way for me to check if the sword is equipped than bool value??